Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate distance between two locations and then display the way?

I need to calculate distance between two locations in my android application. Then I need to display the way on the map.

Looks like I need to use some Google API to calculate the distance. Should it be Google Directions API? Android documentation says that I should use Google Maps External Library, but I don't see there any method for the same. Probably, if I want just to calculate the distance between two points and not walking distance better to use some simplified approach.

Then to display the map - what is the advantage of usage of MapView compared with opening according url in user's browser? Would like to avoid the following actions:

When you are ready to release your application, you must register your release certificate with the Google Maps service and obtain a new Maps API Key. You must then change the MapView elements in your application to reference the new API key.

like image 475
LA_ Avatar asked Nov 20 '25 08:11

LA_


2 Answers

You could also just do this:

//your two locations
Location locationA;
Location locationB;

//distance between them
float distanceBetweenPoints = locationA.distanceTo(locationB);

bit late but hopefully this helps :)

like image 77
Ian Avatar answered Nov 21 '25 23:11

Ian


The distance between two points can be found by using the equation described here: http://williams.best.vwh.net/avform.htm#Dist remember, use radians, not degrees!

It seems you have concern about updating a maps key in each release? I have an app in the market that is map-based, and you get 1 prod key and 1 debug key (I believe it's per developer, but if not, it's per app). It has to do with the key you use to sign your apk. What I'm saying is that if you get your prod api key, and only ever develop this one app, you can publish many many updates without ever having to touch the key again (assuming you don't do debug-key testing locally). If you're concerned about it, you can keep both in your AndroidManifext.xml file and just comment out the irrelevant one, depending on whether you're deploying to a device or emulator.

like image 22
Travis Avatar answered Nov 21 '25 23:11

Travis



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!