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?
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>
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.
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.