Call Google Map apps from an Android app to get the direction of rotation


I need to show the direction of movement using an external Google map application. I found this link http://developer.android.com/guide/appendix/g-app-intents.html , but below the Maps application opens at the specified location

Uri uri = Uri.parse("geo:13.070984,80.253639"); Intent in = new Intent(Intent.ACTION_VIEW, uri); startActivity(in); 

I need to know if there is a way to transfer two geographical locations in order to get the direction of travel.

+4
source share
3 answers

yes, it’s very easy to show the direction if you have the latitude and longitude of both the source and destination. Just review the following code:

 Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+latitude_source+","+longitude_source+"&daddr="+latitude_dest+","+longitude_dest)); startActivity(intent); 

Where latitude_source=Latitude your source longitude_source=Longitude your source latitude_dest=Latitude your destination longitude_dest=Longitude your destination

Just replace these values ​​with your actual data. . Use the above code for a specific event.

Hope this helps you.

+13
source

I implemented this by firing an intention using the Google Maps URL - the Maps application selects it and it works. I think this is not officially recommended, but works well for me.

 Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(String.format(http://maps.google.com/maps?saddr=%s&daddr=%s, startAddress, endAddress))); startActivity(intent); 

The above works for the NAMES location, you may need to configure it to use lat / long. Here is an example of a Google Maps URL between two lat / long points that will be useful: http://maps.google.co.uk/maps?f=d&source=s_d&saddr=A685&daddr=M40&hl=en&geocode=FazjPwMdRKPc_w%3BFeS8Ggmedrmfrsmrmrmrmrmrmrmrmrmrmrmrmrmrmrmr 1,0 & sz = 5 & sll = 53.800651, -4.064941 & sspn = 22.244994,67.631836 & ie = UTF8 & t = h & z = 5

0
source

You can get routing between two locations with the following URL.

https://maps.google.com/maps?saddr=kedah&daddr=johor

saddr is the start, and daddr is the destination.

Code example:

 Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(String.format("http://maps.google.com/maps?saddr=kedah&daddr=johor"))); startActivity(intent); 
0
source

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


All Articles