简体   繁体   English

Google Places API获取Android中附近地点的距离

[英]Google places api get distance of nearby places in android

I cannot find way to sort my nearest places according to distance in android. 我找不到在android中根据距离对我最近的地方进行排序的方法。 I also want to show that distance on listview with name of places. 我还想在列表视图上用地点名称显示该距离。 Can anyone help me to do this.??? 谁能帮我做到这一点。

Here is my function to search plaaces: 这是我搜索地点的功能:

public PlacesList search(double latitude, double longitude, double radius, String types)
        throws Exception {

    this._latitude = latitude;
    this._longitude = longitude;
    this._radius = radius;

    try {

        HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
        HttpRequest request = httpRequestFactory
                .buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
        request.getUrl().put("key", API_KEY);
        request.getUrl().put("location", _latitude + "," + _longitude);
        request.getUrl().put("radius", _radius); // in meters
        request.getUrl().put("sensor", "false");
        if(types != null)
            request.getUrl().put("types", types);

        PlacesList list = request.execute().parseAs(PlacesList.class);
        // Check log cat for places response status
        Log.d("Places Status", "" + list.status);
        return list;

    } catch (HttpResponseException e) {
        Log.e("Error:", e.getMessage());
        return null;
    }

}

尝试添加以下内容:

request.getUrl().put("rankby", "distance");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM