Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open google maps through intent for specific location in android

I'm designing one application in which I want to show specific location on Map. I'm passing String of address which is already placed on Google Map. Following is my Intent code..

String url = "http://maps.google.com/maps?daddr="+address; Intent intent = new Intent(android.content.Intent.ACTION_VIEW,  Uri.parse(url)); startActivity(intent); 

But it gives me Google Map for getting direction. I know why that so, because I used daddr in url but I don't know what to use for specific location..Please tell me what to use there..

like image 829
Akshay Avatar asked Mar 28 '14 04:03

Akshay


People also ask

How do I change the default location for opening Google Maps?

Look to the top-left corner of the map, and click the three horizontal menu bars. From the options, select Your places. Next, click Home. Type the name of the location you want to set as your home address in the address field.


2 Answers

I have not tested this but you could try :

First method:

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); context.startActivity(intent); 

EDIT: This might not work with Google maps 7,0

hence you could change the uri to :

Second option:

String geoUri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + mTitle + ")"; 

where mTitle is the name of the location.

Third option:

geo:0,0?q=my+street+address 

Fourth option:

String map = "http://maps.google.co.in/maps?q=" + yourAddress; 

Hope that works and helps :D..

like image 101
Rat-a-tat-a-tat Ratatouille Avatar answered Sep 20 '22 02:09

Rat-a-tat-a-tat Ratatouille


Get Lat-Lng Using this web-service

http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false

Then Pass it to this code

    String strUri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + "Label which you want" + ")";     Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(strUri));      intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");      startActivity(intent); 

I hope it will help you

Thank you.

like image 32
Darshak Avatar answered Sep 18 '22 02:09

Darshak