Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

open iPhone map app ?

Hi,
I am willing to add a "get directions" in my app, but as it is not possible from inside the app (correct me if I am wrong), I would like to open the iPhone map (or plan ?) app with lat and long in parameters ?

Is it possible at all ? Or I'll have to set a webview with Google Maps ?

Would be great if it would work for Android too !

Thanks !

— asked June 25th 2010 by Jean-Philippe Boily
  • directions
  • getdirections
  • iphone
  • map
0 Comments

3 Answers

  • Accepted Answer

    Ti.Platform.openURL('http://maps.google.com/maps?daddr={address here}&ie=UTF8&t=h&z=16');

    You just open the url and the iPhone will automatically open the native map application. In the stimulator, safari is opened.

    — answered June 25th 2010 by Sj Singh
    permalink
    1 Comment
    • I cant able to open ios native map, here is my code

      Ti.Platform.openURL('http://maps.google.com/maps');
      

      this is opening in safari.
      I am using Titanium 1.7.5

      — commented March 29th 2012 by Karthi Ponnusamy
  • The answer from Sj Singh is a bit outdated. I had the same problem while working on my map app and found a better solution.

    For iOS you will need to use Ti.Platform.openURL() as mentioned in the previous answer but the URL scheme is different now that Apple offers their own native map solution.

    Ti.Platform.openURL("http://maps.apple.com/?saddr=[Start Address]&daddr=[Destination Address]")
    

    I believe the starting address is optional. I would recommend this url scheme since Apple now has a native map app available on iOS devices (no longer can depend on Google map app).

    For Android you will need to use an Intent like this:

    var mapIntent = Ti.Android.createIntent({
        action : Ti.Android.ACTION_VIEW,
        data : "http://maps.google.com/maps?saddr=[Start Address]&daddr=[Destination Address]"
    });
    Ti.Android.currentActivity.startActivity(mapIntent);
    

    Android supports the geo: url scheme but it is not fully implemented yet. I'm using these solutions for our map app template and they both work out fine.

    Hope this helps anyone who comes across this question.

    — answered August 5th 2013 by Henry Belmont
    permalink
    2 Comments
    • an intent is not needed to launch the maps app. This will work (tested on android 4.x)

      Ti.Platform.openURL('https://maps.google.nl/maps?q='+adress);

      — commented September 6th 2013 by han woolderink
    • If you want to open a location in a third party maps app without a start / destination use:

      IOS : Ti.Platform.openURL('http://maps.apple.com/?q='+address);

      Android

      var intent = Ti.Android.createIntent({
          action: Ti.Android.ACTION_VIEW,
          data:'geo:0,0+?q='+ Ti.Network.encodeURIComponent(address)
      });
      //Start new activity
      Ti.Android.currentActivity.startActivity(intent);
      

      OR : Ti.Platform.openURL('https://maps.google.nl/maps?q='+address);

      — commented August 5th 2015 by Gerben Hofman
  • Thanks a lot. It really helped me

    — answered June 26th 2014 by Waqas Karim
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.