Comparing two locations using their Longitude and Latitude

前端 未结 3 1992
忘了有多久
忘了有多久 2020-12-02 17:38

Hi i need to cal an event at onchangelocation(), by comparing current latitude and longitude with some saved latitude and longitude but i m getting an error. eclipse is not

3条回答
  •  囚心锁ツ
    2020-12-02 18:22

    You can use the Location class's static distanceBetween() method like so:

        float[] distance = new float[1];
        Location.distanceBetween(lat, lon, currentLat, currentLon, distance);
        // distance[0] is now the distance between these lat/lons in meters
        if (distance[0] < 2.0) {
            // your code...
        }
    

    If you have two Location objects, another option is distanceTo()

提交回复
热议问题