I have a problem with my application. I want to open Google Maps with defined in code location, so I set the data to the intent, but maps open on my location all the time (not the specified in code one).
Here is the code:
String addressString = "1600 Amphitheatre Parkway, CA";
Uri locationUri = new Uri.Builder();
.scheme("geo")
.path("0,0")
.query(addressString);
.build();
Intent mapIntent = new Intent(Intent.ACTION_VIEW, locationUri);
mapIntent.setPackage("com.google.android.apps.maps");
if(intent.resolveActivity(getPackageManager()) != null)
startActivity(mapIntent);
Does anyone know how to handle this situation? I tried on my phone and on the virtual device and it's not working on both.
Use it this way to open with latitude and longitude:
double lat = YOUR_LATITUDE;
double lng = YOUR_LONGITUDE;
String placeLabel = YOUR_PLACE_LABEL;
String uri = String.format(Locale.ENGLISH, "geo:%f,%f?q=%f,%f(%s)", lat, lng, lat, lng, placeLabel);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
If you want to open the map with an address, replace de uri with:
geo:0,0?q=my+street+address
Change query(addressString)
to appendQueryParameter("q", addressString)
and you will rich what you want:
Uri locationUri = new Uri.Builder()
.scheme("geo")
.path("0,0")
.appendQueryParameter("q", addressString)
.build();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.