简体   繁体   English

位置经理

[英]Location Manager

Can we use android location https://developer.android.com/reference/android/location/Location.html 我们可以使用android位置https://developer.android.com/reference/android/location/Location.html

inside the java standalone application. 在Java独立应用程序内部。 I have to find the distance between two lat/lng pairs. 我必须找到两个纬度/经度对之间的距离。 Now i am using 现在我正在使用

public double Haversine(double lat1,double lon1,double lat2,double lon2)
    {
        double R = 6372.8; // Earth Radius in Kilometers

        double dLat = Deg2Rad(lat2 - lat1);
        double dLon = Deg2Rad(lon2 - lon1);

        double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2) +
                Math.cos(Deg2Rad(lat1)) * Math.cos(Deg2Rad(lat2)) *
                Math.sin(dLon / 2) * Math.sin(dLon / 2));
        double c = (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
        double d = R * c;
        // Return Distance in Kilometers
        return d;
    }
    public double  Deg2Rad( double deg) {
 public double  Deg2Rad( double deg) {
        return  (deg * Math.PI / 180);
    }

But the above code gives the air distance. 但是上面的代码给出了空中距离。 But i need roadway distance. 但是我需要行车距离。 Please help me out.. thanks in advance 请帮帮我..在此先感谢

You can do this using Directions API of Google Maps 您可以使用Google Maps的Directions API进行此操作

https://developers.google.com/maps/documentation/directions/ https://developers.google.com/maps/documentation/directions/

Good example is : http://javapapers.com/android/draw-path-on-google-maps-android-api/ 很好的例子是: http : //javapapers.com/android/draw-path-on-google-maps-android-api/

This is example of Distance API of Google Map, but you can refer to it and use Directions API in same way 这是Google Maps Distance API的示例,但是您可以参考它并以相同方式使用Directions API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM