开发者

how to get differnce between two gps address

I have two longitude and latitude values. i.e.,

longitude1 and latitude1 are came from webservice

and longitude2 and latitude2 are my device values.

So i want to calculate the difference between these two address. So i tried below code

private Geocoder geocoder;

geocoder=new Geocoder(this);

Address address1=geocoder.getFromLocation(latitude1,longitude1,1).get(0);

Address address2=geocoder.getFromLocation(latitude2,longitude2,1).get(0);

So i want to know difference between address1,address2. So please tell me how to find the d开发者_开发技巧ifference between address1, address2.

Thanks in advance.

Best Regards


Use the following method
Location.distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results);

so the result[0] has the approximate distance in meters between two locations.


Actually, you'll have to use the following to properly calculate the value.


As you already have the latitudes and longitudes captured (latitude1, longitude1) simply subtract the 1 and 2 and take the Math.abs() value as your distancex, distancey. then apply pythagoras to find the actual distance. http://en.wikipedia.org/wiki/Pythagorean_theorem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜