Hi,
I am trying to get map links in my app to open natively on the respective platforms. Currently it opens on both iOS and Android in a browser version of google maps. Rather than that I would like to have it open with the native apps on the device.
I figured out that I can force it by using "geo:0,0?q=Location"
for android and "maps:q=location"
for ios.
Is there a way to have the application check what os the app is running on and open the respective link format? or does anyone know a better way of doing this?
Thanks.
I was able to do this use the cordova device plugin,
var location;
var phoneModel = device.platform;
if (phoneModel === 'Android') {
location = '_system';
} else if (phoneModel === 'iOS') {
location = '_blank';
} else {
location = "_blank";
}
window.open($scope.pet.manual, location);
so currently i have this which is setup to open google maps on android devices.
$scope.openMapForDirections = function () {analytics.trackEvent('Directions', '', $scope.truck.name.split('(')[0], 0);
if (!$stateParams._geoloc) {
$ionicPopup.alert({
title: ' Error',
content: "No Location provided",
okType: 'prompt-button-default'
});
return;
}
if ()
navigator.geolocation.getCurrentPosition(function (_pos) {
var url = "geo:0,0?q=" + _pos.coords.latitude + ",";
url += _pos.coords.longitude + "&daddr=" + $stateParams._geoloc[1] + "," + $stateParams._geoloc[0];
window.open(url, '_blank', 'closebuttoncaption=Return', 'enableViewportScale=yes', 'location=no');
});
};`
how would I implement your solution with what I have? Thanks in advance.
I’m curious, is this better than $ionicPlatform.is(‘android’) ?
Alright, you would create your variables, geo
and map
, and just adjust there value in an if statement.
var geo;
var map;
if (phoneModel === 'Android') {
//adjust geo here
} else if (phoneModel === 'iOS') {
// adjust map here
} else {
//do nothing.
}
$ionicPlatfrom.is()
is basically the same thing as what I’m doing with cordova’s device plugin. My example was from an older project before that api was introduce
Should i be using $ionicPlatform.is(‘android’) instead?
Use $ionicPlatform
because it is properly set up and you can inject it in your controller and not have any chance for errors
How would I do that?
.controller('ExampleCtrl', function($scope, $ionicPlatfrom) {
var geo;
var map;
if ($ionicPlatfrom.is('android')) {
//adjust geo here
} else if ($ionicPlatfrom.is('ios')) {
// adjust map here
} else {
//do nothing.
}
});
http://ionicframework.com/docs/api/utility/ionic.Platform/
This is seems a better way.