Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Google Maps app

I'm trying to launch Google maps from my application. I'm using:

GeoPoint center = _mapView.getMapCenter(); 

Uri uri = Uri.parse("geo:"+center.getLatitudeE6()+","+center.getLongitudeE6()); 

Log.d(LOG_TAG, "Launching Google Maps with Uri: ("+uri+")"); 
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent); 

I tested it with a map centered on somewhere in NYC, however Google maps opens not centered there. I followed Android Developer's site reference to use: "geo:latitude,longitude" pattern.

the log that you see prints:

Launching Google Maps with Uri: (geo:40763500,-73979305) 

anyone knows what can be the problem?

like image 974
oriharel Avatar asked Dec 20 '25 08:12

oriharel


2 Answers

Try to use:

Uri uri = Uri.parse("geo:"+(center.getLatitudeE6()/1E6)+","+(center.getLongitudeE6()/1E6)); 

The geo: Uri format takes decimal latitude/longitude and not E6 format (degrees * 1E6).

like image 83
systempuntoout Avatar answered Dec 22 '25 22:12

systempuntoout


You need to divide by 1E6 since GeoPoint doesn't return a double.

Uri uri = Uri.parse("geo:"+(center.getLatitudeE6()/1E6)+","+(center.getLongitudeE6()/1E6));

I like this way personally where daddr would be (center.getLatitudeE6()/1E6)+","+(center.getLongitudeE6()/1E6)

startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?f=d&saddr="+saddr+"&daddr="+daddr+"&hl=en")));
like image 42
Billy Bob Bain Avatar answered Dec 22 '25 23:12

Billy Bob Bain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!