2

I am trying to open Apple Maps in my PhoneGap app when a user clicks on a link. The URL scheme in Apple's documentation is like http://maps.apple.com/maps?ll=51.83733,-8.3016, which opens Apple Maps if it is present, else redirects to Google Maps. But when I click on this link, it opens Google Maps Web App instead, and there is no way to go back to the app.

Searching for a solution, I found this SO question - Phonegap - Open Navigation Directions in Apple Maps App It suggests using maps: instead of http://maps.apple.com/?q=somePlaceName. This works fine and opens the native Apple Maps app. But I want to pass latitude and longitude instead of a place name.

I tried with maps?ll:51.84,-8.30, but it doesn't work.

Community
  • 1
  • 1
a_rahmanshah
  • 1,636
  • 2
  • 22
  • 35
  • Does this question really have anything to do with google-maps? – geocodezip Jan 30 '14 at 05:15
  • PhoneGap opens up the Google Maps web view. And also, i have edited the question too many times to add a tag for PhoneGap and also to move the `corodva` tag in front, but it gets removed automatically. – a_rahmanshah Jan 30 '14 at 05:59

1 Answers1

7

You need to add the InAppBrowser plugin to your project and open the link with the system web browser, which will automatically redirect to Apple Maps:

var mapLocationUrl = 'maps.apple.com/?ll=51.84,-8.30';
var ref = window.open(encodeURI(mapLocationUrl), '_system', 'location=no');

Check the official Apple URL Scheme Reference for the complete list of parameters.

Paolo Moretti
  • 54,162
  • 23
  • 101
  • 92
Nijil Nair
  • 1,608
  • 1
  • 11
  • 14
  • Hi Nair! If you read my question again, I am using the same URL that you have mentioned, but it opens up Mobile Google Maps web app. – a_rahmanshah Jan 30 '14 at 13:08
  • hope u tried exactly as written. I used iOS 6.1 and used inAppBrowser to call browser instance and it automatically redirects to apple map app. See the code var mapLocationUrl = 'http://maps.apple.com/?ll=51.84,-8.30'; var ref = window.open(encodeURI(mapLocationUrl), '_system', 'location=no'); – Nijil Nair Jan 31 '14 at 06:14
  • @Nair It works fine and opens Apple Maps when I open this page in Safari on my Map. You mean inAppBrowser inside PhoneGap app? – a_rahmanshah Jan 31 '14 at 06:54
  • 1
    Yes, use inAppBrowser API in phonegap. – Nijil Nair Feb 01 '14 at 08:53
  • Hi Nijil, I used inAppBrowser and it worked fine. Please update your answer so I can mark it as accepted. Thanks a lot! – a_rahmanshah Feb 03 '14 at 08:03