Distance between geopoints

后端 未结 3 968
甜味超标
甜味超标 2021-01-05 10:42

I have a problem calculating the distance between two geopoints.

The geopoints are:

position1 = mapView.getProjection().fromPixels(
(int) e.getX(),
(         


        
3条回答
  •  孤城傲影
    2021-01-05 11:39

    you are set the GeoPoint value into the Location object instead of double value try to set as double value of Latitude and Longitude

    Location loc = new Location("");                                
    
    loc.setLatitude(35.1064);
    
    loc.setLongitude(22.556412);
    
    Location loc2 = new Location("");                               
    
    loc2.setLatitude(22.556412);
    
    loc2.setLongitude(35.1064);
    

    now get the location

    float distance = loc.distanceTo(loc2);
    

提交回复
热议问题