How can I get the distance between two point by latlng?

前端 未结 3 391
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 09:49

I want to get the distance from A to B by latlng.When i run my app with the following code,it return a wrong result. Fx i tryed A( 31.172740,115.0081630) ,then B(30.6055980,

3条回答
  •  既然无缘
    2020-12-06 10:17

    LatLng startLatLng = new LatLng(startLatitude, startLongitude);
    LatLng endLatLng = new LatLng(endLatitude, endLongitude)
    double distance = SphericalUtil.computeDistanceBetween(startLatLng, endLatLng);
    

    also add

    compile 'com.google.android.gms:play-services-maps:15.0.1'
    compile 'com.google.maps.android:android-maps-utils:0.5+'
    

    to your gradle dependencies

    Distance in meters

提交回复
热议问题