Starting Google Maps App with provided location an

2020-02-24 13:29发布

From my app I would like to start the Google Maps App with a provided location and a marker. The marker should indicate, that there is something on that given location.

For now, I have the following code, which starts with an Intent the Google Maps App with the provided location (51.49234, 7.43045).

startActivity(
new Intent(
    android.content.Intent.ACTION_VIEW, 
    Uri.parse("geo:51.49234,7.43045")));

When the Google Maps App starts, it looks like the following: enter image description here

No marker is shown. I would like, that the Google Maps App would show a marker on that position, which is given through the Intent. Is there any "hidden" Intent URI's which I can use to show a marker within the Google Maps App?

Thanks in advance.

Solution

@Rajiv M. pointed me to the idea of querying the surroundings with the given location.

So, the solution is: Query the surroundings of your given location with your given location as the parameter. The URI looks like:

geo:51.49234,7.43045?q=51.49234,7.43045

Google Maps will show the query-result as the street name: enter image description here

Kind of a hack, but it seems to work well.

Why you should not use 0,0 as the map location

geo:0,0?q=51.49234,7.43045

When you start Google Maps App with the provided map location point 0,0 , Google Maps App will start searching for your current device position. And this takes time. In some cases, when GPS signal is not provided, way too much. Until then the Google Maps App will start searching for your query 51.49234,7.43045.

2条回答
ゆ 、 Hurt°
2楼-- · 2020-02-24 13:43

Maybe you can try to put ur uri as below: Uri uri =Uri.parse("http://maps.google.com/maps?q=" +_lat +","+_lon);

At least the above code work for me. It help me add a pin point on top of the location i search for. furthermore, the pin point will have a small dialog box to press on, it provide me the function of searching the direction to that location. :D

查看更多
趁早两清
3楼-- · 2020-02-24 14:00

Try starting Google Maps using the same intent, but with a URI of the format:

geo:34.067214,-118.349332?q=410+Hauser+Boulevard,+Los+Angeles,+CA

i.e. geo:0,0?q=street+address

The application should then actually show a point at that address. If you do not have the address, you may have to use a service to translate it to an address for this to work.

-

The other option is to embed a MapView in your application and add a marker within that. A tutorial for using MapViews / Markers with-in your application can be found at http://mobiforge.com/developing/story/using-google-maps-android.

查看更多
登录 后发表回答