谷歌将api与android附近的地方保持距离

时间:2014-09-12 15:01:47

标签: java android google-maps-api-3

我无法找到根据android中的距离对最近的地方进行排序的方法。我还想在列表视图上显示该位置的距离。任何人都可以帮我这样做。???

这是我搜索平台的功能:

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;
    }

}

1 个答案:

答案 0 :(得分:0)

尝试添加以下内容:

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