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.
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.
-
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);
-
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 destinationhttp://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);
-
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?
-
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.
-
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
-
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 :))
-
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.
-
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!
-
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.
-
user the region object
e.g.
var region = { "latitude" : 1.352090, "longitude" : 103.1213133, "latitudeDelta" : 0.01, "longitudeDelta" : 0.01 };
-
Link to Maps API: https://developer.appcelerator.com/apidoc/mobile/1.0/Titanium.Map