How can I open Google Maps(using Intents or adding Google Maps into my application) with address? I have the address, but I don\'t have latitude/longitude. How can I do it? Than
Change the bold part of this URL to your company address. It's best if you replace all spaces with a plus (+) character, but should work with spaces too: http://maps.google.com/maps/geo?q=620+8th+Avenue,+New+York,+NY+10018,+USA&output=csv&oe=utf8&sensor=false
Raise a request to above URL. For more information refer http://androidadvice.blogspot.in/2010/09/asynchronous-web-request.html
This will generate a code that looks something like this:
200,8,40.7562008,-73.9903784
The first number, 200, says that the address is good. The second number, 8, indicates how accurate the address is. The last two numbers, 40.7562008 and -73.9903784, are the latitude and longitude of this address. Use these to get your google map working.
Note : The above steps have been copied from http://webdesign.about.com/od/javascript/ss/add-google-maps-to-a-web-page_2.htm
Little late to the party. I prefer @st0le's answer but URLEncoder.encode(String s)
is deprecated as of API 16. You need to pass a second argument as well. Check the answer below.
public static Intent viewOnMapA(String address) {
try {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:0,0?q=%s",
URLEncoder.encode(address, "UTF-8"))));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
You can use Google Geocoding API, which converts your physical address into latitude and longitude. API returns it into XML or JSON format. You just need to parse the data to get latitude and longitude. After receiving latitude and longitude you can load it on mapview.
Geocoding api link :
https://developers.google.com/maps/documentation/geocoding/
Hope this helps.
String geoUri = "http://maps.google.com/maps?q=loc:" + addressName;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
context.startActivity(intent);
As of 2017 the recommended by Google approach is using the Google Maps URLs API that provides universal cross-platform URLs. You can use these URLs in your intents.
Example of such URL from the documentation:
https://www.google.com/maps/search/?api=1&query=centurylink+field
Hope this helps!
From my personal Code Library. ;)
public static Intent viewOnMap(String address) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:0,0?q=%s",
URLEncoder.encode(address))));
}
public static Intent viewOnMap(String lat, String lng) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:%s,%s", lat, lng)));
}