How to launch a map target using a marker / overlay element at a given latitude and longitude?

I have latitude and longitude, and I want to open Google maps concentrated at this point. Therefore, I use the following code for it:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:"+lat +","+lng)); startActivity(intent); 

However, this does not center the marker. I want to place some kind of marker at the point where I start (and maybe some name for it). Any idea how this can be achieved?

+6
source share
2 answers

You can use it, for example,

Display a specific place,

 Uri uri = Uri.parse("geo:0,0?q=22.99948365856307,72.60040283203125 (Maninagar)"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); 

Display the route between places,

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+23.0094408+","+72.5988541+"& daddr="+22.99948365856307+","+72.60040283203125)); startActivity(intent); 
+13
source

You can simply put latitude and longitude as additional functions in this intention:

 Intent intent = new Intent(); intent.putExtra("latitude", latitude); intent.putExtra("longitude", longitude); startActivity(intent); 

And then extract them from the MapActivity launch:

 Intent intent = getIntent(); double latitude = intent.getDoubleExtra("latitude", 0.0); double longitude = intent.getDoubleExtra("longitude", 0.0); 

You can then use these values ​​for anything. Hope this helps.

-2
source

Source: https://habr.com/ru/post/908307/


All Articles