How to open default map app?

Hello,
I need to open default map app of device (ios, windows phone, android) with 1 link.
When user click in a marker there is the message “click here for open your default navigator”… And it should open the navigator with directions and it should start! :smile:

2 Likes

Sorry if I up this but i still need this! :frowning:

Hello. Here is my code in coffeescript, but you can probably work it out:

 $scope.openMap = ->
  address = $scope.vm.article.addresses[0]
  lat = parseFloat(address.loc.lat)
  long = parseFloat(address.loc.lng)
  text =  encodeURIComponent(address.text)
  if ionic.Platform.isIOS()
    window.open("http://maps.apple.com/?q=#{text}&ll=#{lat},#{long}&near=#{lat},#{long}", '_system', 'location=yes')  
  else
    window.open("geo:#{lat},#{long}?q=#{text}", '_system', 'location=yes')

you will also need to install org.apache.cordova.inappbrowser plugin for this to work

Thank you very much!
:smiley:

ciao uncusino, have you solved?

yes, I have! :coffee:

please can you tell me how?

window.location.href = "maps://maps.apple.com/?q="+lat+","+lon;

lat = latitude
lon = longitude
(the same with google maps but you put gmaps link)

Thank you so much. I’ll try it as soon as I can.
Have I to add your string in the link?:

< // a window.location.href = “maps://maps.apple.com/?q=”+lat+","+lon; > OPEN IN MAP APP <///a>

This is how I made it work (using cordova “device” but you can use ionic.Platform ):

var address=data.street+", "+data.city+", "+data.state;
var url='';
if(device.platform==='iOS'||device.platform==='iPhone'||navigator.userAgent.match(/(iPhone|iPod|iPad)/)){
	url="http://maps.apple.com/maps?q="+encodeURIComponent(address);
}else if(navigator.userAgent.match(/(Android|BlackBerry|IEMobile)/)){
	url="geo:?q="+encodeURIComponent(address);
}else{
	//this will be used for browsers if we ever want to convert to a website
	url="http://maps.google.com?q="+encodeURIComponent(address);
}
window.open(url, "_system", 'location=no');
2 Likes

In addition to the answers given, if you had an address string rather than lat-longs, you would use for iOS:

function launchDirections(address) { window.location.href = "maps://maps.apple.com/?daddr=" + address; }

where address would be a string like: “24 Spring Street, New York, NY”