0

I'm trying to make a maps call from my ionic framework app. In my html file I use:

<a ng-href="maps://?q={{dest.Latitude}},{{dest.Longitude}}">Maps</a>
<div>{{dest.Latitude}},{{dest.Longitude}}</div>

In my controller the data for dest looks like this:

{"Latitude":12.34567, "Longitude":1.23456}

The latitude and longitude are shown in the div correctly.

But I get an error if I click on the link:

Failed to load webpage with error: The URL can't be shown

I also tried to cast the lat and long to string but it had no effect on it.

If I use static geocordinates like this everything works fine:

<a ng-href="maps://?q=12.34567,1.23456">Maps</a>

What am I missing?

Kingalione
  • 4,237
  • 6
  • 49
  • 84

3 Answers3

1

You have to add map in to href Sanitization white list.

example code:

angular.module('app',[])
.config(
    function( $compileProvider ){   
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension|map|geo|skype):/);
    }
);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
    <a ng-href="map:lat=51.527141,lon=-0.087853">Map</a>
    <a ng-href="skype:username">Skype</a>
</div>

CompileProvider Docs

jad-panda
  • 2,509
  • 16
  • 22
  • If I use the $compileProvider sanitization I cant even go to the details view. It also gives me a error "Failed to load webpage with error: The URL can't be shown" if I try to got the the details view. – Kingalione May 15 '15 at 11:44
  • I tested it in iPhone emulator and its working fine. can you tell little bit more about where and how its failing ? – jad-panda May 15 '15 at 12:48
1

Well the compileProvider solution didn't worked for me so I made a workaround.

In my controller I use:

$scope.navigate = function(){
    var geoString = 'maps://?q='+dest.Latitude+','+dest.Longitude+'';
    window.open(geoString, '_system');
  };

And I'm calling the function like here:

<button ng-click="navigate()" class="button button-icon ion-earth"></button>

This works. I think there is a problem with data binding in the href.

Kingalione
  • 4,237
  • 6
  • 49
  • 84
0

Just to be sure, are testing it on a iOS device? If I'm not mistaken the maps:// protocol only works on iOS with Apple Maps.