如何在单个请求中附近搜索多个位置谷歌地方api

时间:2013-01-19 00:57:54

标签: google-maps google-places-api google-places

我希望使用google places api附近的搜索来获取多个特定位置。使用NAME参数查询多个位置的格式是什么。 api在单个位置显示以下内容:

     https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

我在文档中读到你可以通过附加一个|来指定多种类型

如何在google place api附近搜索中指定多个名称参数?

2 个答案:

答案 0 :(得分:0)

如果要使用多种类型进行搜索,可以使用按位OR运算符。请参阅我使用3种不同类型的最后一行。 这是一个例子

private String getUrl(){

    StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
    if(mLastLocation != null){
        sb.append("location=" + mLastLocation.getLatitude() + "," + mLastLocation.getLongitude());
    }
    sb.append("&radius=" + searchWithin);
    sb.append("&sensor=true");
    sb.append("&key=" + getString(R.string.map_api_key));
    sb.append("&types=" + "restaurant|atm|bank");

    return sb.toString();
}

答案 1 :(得分:-1)

您必须在请求变量的“名称”字段中指定不同的名称。用|分开它们并用引号括起来。

var request = {
  location: new google.maps.LatLng(-33.8665433,151.1956316),
  radius: '500',
  name: "name1|name2|name3",
  types: ['store']
};

service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);

https://developers.google.com/maps/documentation/javascript/places#place_search_requests