How to Sort Geo-points according to the distance from current location in Android

前端 未结 4 1983
星月不相逢
星月不相逢 2020-12-04 20:44

I have a \"Place\" object with a LatLng coordinate for each:

import com.google.android.gms.maps.model.LatLng;

public class Place{
    public String name;
           


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 20:59

    As you got your current location, You can sort by calculating the driving distance (which is most suitable for places like restaurants ) as follows,

    1. Calculate the distance to each object

      http://maps.googleapis.com/maps/api/directions/json?origin="+yourLat+","+yourLong+"&destination="+toLat+","+toLong+"&sensor=false&mode=DRIVING
      
    2. Once you calculate each distance , apply some simple sorting algorithm for those distances.

提交回复
热议问题