Comparing two locations using their Longitude and Latitude

前端 未结 3 1986
忘了有多久
忘了有多久 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:16

    All the 4 input parameters are in float. Distance is a relative one not real distance. You need to convert this distance to a real distance by searching some formula online :( I used this in my app to get nearest metro station from my current location. Hope this snippet helps someone :)

    float distance(float lat,float lon,float clat,float clon)
    {
        float distance;
        float temp1;
        float temp2;
        temp1=(float)((lat-clat)*(lat-clat));
        temp2=(float)((lon-clon)*(lon-clon));
        distance=temp1+temp2;
        return distance;
    }
    

提交回复
热议问题