How to find distance using google places api

I am developing an application using the Google pLaces api. I can get a list of cafes that is next to the user who uses my application. the resulting list contains information about places such as the name of the place, its address, longitude values ​​and longitude phone number. What I want to know is how I request api api to return the distance between the user and each of the entries in the result list. I looked at several links posted on stackoverflow that discuss a similar topic. I also looked at the documentation in Google, but nothing is said about getting these distances. I want to refrain from using any mathematical formula, such as the big circle algorithm, because in this case the distance traveled will be the direct distance and this will not be an accurate estimate of the distance. so someone please tell me how to request api places to give me the distance between user and each record as a result?

The few links I went through were: How do I find the distance between one place in another using the Geolocation or Similiar API without embedding a Google map?

find distance in kilograms in Android using google places api

How to get a remote kilometer in android?

+4
source share
5 answers

I think, as you said, you want to refrain from using

any math formula so you can also try this -

You can get the distance from the location address

http://maps.googleapis.com/maps/api/distancematrix/xml?origins="+a+"&destinations="+b+"&mode=driving&language=en-EN&sensor=false with a=addressFrom, b=addressTo 

If you have lat, long location, you can get the address of this location as:

  double latiTude = 10.3929393; double longiTude = 150.93984884; Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault()); GeoPoint p= new GeoPoint((int) (latiTude * 1E6), (int) (longiTude * 1E6)); List<Address> address = geocoder.getFromLocation( p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6, 1); if (address.size() > 0) { String addressFroLatLong= ""; for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++) { addressFroLatLong+= address.get(0).getAddressLine(i) + "\n"; } } 

PLease upvote if helped. Nothing more. Thanks, glad to help you enjoy.

+3
source

The Haversin implementation is given below. However, I still feel that there should be some kind of service offered by google places api that will help find the exact distance between the two points. if anyone knows that then pl let me know .. Haversine is a good replacement for now.

 import java.lang.*; import java.io.*; import java.math.*; public class DistanceCalculation { public static void main(String[] args) { double lon11 =-97.116121; double lat11=32.734642; double lon22=-97.111658; double lat22=32.731918; // calculateDistance(lat11,lon11, lat22, lon22); distFrom(lat11, lon11, lat22, lon22); } public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; double dLat = Math.toRadians(lat2-lat1); double dLng = Math.toRadians(lng2-lng1); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); double dist = earthRadius * c; System.out.println(dist); return dist; } } 
+2
source

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

It seems that you have a problem with updating the card key in each version? I have a map-based application on the market and you get 1 prod key and 1 debug key (I think this is for the developer, but if not, this is for the application). This is due to the key that you use to sign your apk. I say that if you get your prod api key and only ever develop this application, you can publish many updates without having to touch the key again (if you are not doing local testing of the debug key), If this bothers you, you can save both in your AndroidManifext.xml file and just comment irrelevant, depending on whether you are deploying to a device or emulator.

0
source

Calculating between two geographical locations is easy, especially for your tasks, to find the distance to hotels nearby.

You can use the haversine formula, which is perfect for your task.

But these geographic formulas give the air distance, not the distance to the road for which you need a routing service.

0
source

Another solution: You can also just do this:

 //your two locations Location locationA; Location locationB; //distance between them float distanceBetweenPoints = locationA.distanceTo(locationB); 

a little late, but hopefully this helps :)

-1
source

All Articles