Titanium Community Questions & Answer Archive

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

Link to Native Google Maps

Anyone know the proper way to open an address in the native Google Maps application from an application?

Right now I'm opening the address in a webview but don't really like that…

Thanks.

— asked March 12th 2010 by John Welch
  • google maps
  • maps
  • native
0 Comments

12 Answers

  • Hi

    if you want to use the native android google map app, you can do like this:

    var address = "put your adresse here";
    var lblAddress = Titanium.UI.createLabel({
        text: "link an adress :)",
        color: 'blue',
        font: {
            fontSize: 14,
            fontWeight: 'normal'
        },
        width: 'auto',
        textAlign: 'left',
        top: 1,
        left: deviceWidth * 1/100,
        height: 'auto'
    });
    lblAddress .addEventListener('click',function(){
        var intent = Ti.Android.createIntent({
            action: Ti.Android.ACTION_VIEW,
            data:'geo:0,0+?q='+address
        });
        Ti.Android.currentActivity.startActivity(intent);
    });
    

    you just have to put your adresse in the address variable, and write whatever you want in the label.

    — answered June 14th 2011 by Florent Cardot
    permalink
    2 Comments
    • When I try to use an intent (like in the example, I always get the warning message:

      [WARN][ActivityManager(   73)] Launch timeout has expired, giving up wake lock!
      [WARN][ActivityManager(   73)] Activity idle timeout for HistoryRecord{48199658 com.google.android.apps.maps/com.google.android.maps.MapsActivity}
      

      Does anyone know what could be the problem?

      — commented June 30th 2012 by José Júnior
    • PLease can you write us what is the activity code you added to your tiapp.xml file. I just added your code in a controller but i got this error as i didn't add any activity to handle the intent :

      [ERROR] :  TiExceptionHandler: (main) [1,14839] - Message: Uncaught Error: No Activity found to handle Intent { act=android.intent.action.VIEW dat=geo:0,0+?q=102 avenue des champs élysées, 75008, paris }
      [ERROR] :  TiExceptionHandler: (main) [2,14841] - Source:                     Ti.Android.currentActivity.startActivity(intent);
      

      — commented June 23rd 2014 by mobile webdev2014
  • Apparently, the maps application doesn't have a custom maps:// URL scheme as you would expect. It accepts a URL scheme http://maps.google.com/maps instead of the maps://.

    Read: http://developer.apple.com/iPhone/library/featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html

    Just do the Titanium.Platform.openURL(url), and it'll open it.

    Sample code for a route:

    var win = Ti.UI.currentWindow;
    
    var buttonOpenRoute = Ti.UI.createButton({
        title: "Open Route",
        height: 40,
        width: 200,
        top: 10
    });
    
    buttonOpenRoute.addEventListener('click', function(evt) {
        Ti.Platform.openURL("http://maps.google.com/maps?saddr=39.9034,116.3702&daddr=39.9344,116.4123");
    });
    
    win.add(buttonOpenRoute);
    
    — answered March 16th 2010 by Andrew Angelo Ang
    permalink
    0 Comments
  • Hi,

    I hope this help.

    You need to Run on Device and not on Simulator. On the simulator it will open in the browser on the Phone it will open in the Native App.

    saddr = original point
    daddr= is the destination

    http://mapki.com/wiki/Google_Map_Parameters

    var button = Titanium.UI.createButton({
       title: 'Get Directions'
    });
    button.addEventListener('click',function(e)
    {
           if (Titanium.Geolocation.locationServicesEnabled==false)
            {
                Titanium.UI.createAlertDialog({title:'Guerrilla Website Design', message:'You need to be online to view this page.'}).show();
            }
            else
            {
                    Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
                    Titanium.Geolocation.distanceFilter = 10;
                    Titanium.Geolocation.getCurrentPosition(function(e)
                    {
    
                        if (e.error)
                        {
                            return;
                        }
                        var longitude = e.coords.longitude;
                        var latitude = e.coords.latitude;
    
                        var url = "http://maps.google.co.uk/maps?f=d&source=s_d&saddr="+latitude+","+longitude+"&daddr=guerrilla+website+design+leighton+lu7+1je&hl=en&geocode=&mra=ls&sll="+latitude+","+longitude+"&sspn=0.318051,1.056747&ie=UTF8&z=7";
    Ti.Platform.openURL(url);
                        Ti.API.info(url);
    
                    });
    
            }
    });
    Titanium.UI.currentWindow.add(button);
    
    — answered March 31st 2010 by Daniel Hollis
    permalink
    1 Comment
    • i tried to run this piece of code but on click listener is not working,just a button is viewed.as i want to view map on my emulator.

      — commented February 5th 2011 by Ishwari Shah
  • Sorry, not an answer, but a related question: Does (or will) the native map functionality support other Google Map capabilities, i.e., custom marker data etc? Or is it still best to use a webview for this?

    — answered March 13th 2010 by karlo kilayko
    permalink
    0 Comments
  • I understand how to add a mapview to the window (it already has one).

    I want to send them outside of the App, my link button says, "Get Directions".

    So, the user clicks the button it loads up in the native Google Maps application with a certain address in the destination.

    — answered March 12th 2010 by John Welch
    permalink
    0 Comments
  • Sorry, not an answer, but a related question: Does (or will) the native map functionality support other Google Map capabilities, i.e., custom marker data etc? Or is it still best to use a webview for this?

    EDIT: apologies, accidental double post

    — answered March 13th 2010 by karlo kilayko
    permalink
    0 Comments
  • I also want to do that: create a link to the google map application, to compute directions for example. It would be cool!

    (custom annotation markers woold be cool too :))

    — answered March 16th 2010 by Gregoire Marchal
    permalink
    0 Comments
  • i cannot view the map,on executing above piece of code.It does not executes onclick listener.Can any one guide how to view map.

    — answered February 5th 2011 by Ishwari Shah
    permalink
    0 Comments
  • I used Ti.Platform.openURL(url); on Android 4.x on a ASUS Tab. The system asks me how to open the URL. If I choose Browser a window appears where I can now open it in the native Google Maps App!

    — answered November 19th 2013 by Jan Duve
    permalink
    0 Comments
  • You should use the native map view to add the map to a window/view inside your app. It's much faster.

    Great example in Kitchen Sink for this.

    — answered March 12th 2010 by Jeff Haynie
    permalink
    0 Comments
  • user the region object

    e.g.

    var region = { "latitude" : 1.352090, "longitude" : 103.1213133,
    "latitudeDelta" : 0.01, "longitudeDelta" : 0.01 };
    
    — answered March 12th 2010 by Peter Lum
    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.