Google Places Api sort by distance

后端 未结 3 1359
盖世英雄少女心
盖世英雄少女心 2020-12-09 13:56

Currently developing an Android application that returns the closest 20 location to the users current location.

Google Places API is retur

3条回答
  •  盖世英雄少女心
    2020-12-09 14:21

    Maybe you've already solved your problem, but I hope this can help (Focus on what is in bold):

    radius - Defines the distance (in meters) Within Which to return Place results. The maximum allowed is 50 000 meters radius. Note That radius must not be included if rankby = distance (Described below under Optional parameters) is specified.

    rankby — Specifies the order in which results are listed. Possible values are:

    prominence (default). This option sorts results based on their importance. Ranking will favor prominent places within the specified area. Prominence can be affected by a Place's ranking in Google's index, the number of check-ins from your application, global popularity, and other factors.

    distance. This option sorts results in ascending order by their distance from the specified location. When distance is specified, one or more of keyword, name, or types is required.

    according: https://developers.google.com/places/documentation/search?hl=en

    I have understood according to google documentation that you can not simultaneously send arguments "rankby" and "radius", you must use only one of them at the same time, this way you will get the results sorted by distance.

    test the request doing this:

    resourceURI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?
    location="+myLocation.latitude+","+myLocation.longitude+"&rankBy=distance
    &types="+ URLEncoder.encode (types, "UTF-8") + "&sensor = true&
    key = GOOGLE_MAPS_KEY";
    

    to see how you do, good luck!

提交回复
热议问题