javascript Google Maps API - 地点搜索中的多个关键字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19625228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 16:14:11  来源:igfitidea点击:

Google Maps API - Multiple keywords in place searches

javascriptgoogle-mapsgoogle-maps-api-3

提问by CyberJunkie

Is it possible search multiple individual keywords in one place search request using Google Maps JavaScript API v3?

是否可以使用 Google Maps JavaScript API v3 在一个地点搜索请求中搜索多个单独的关键字?

In the Google Places API documentation it states that multiple keywords can be used https://developers.google.com/places/training/additional-places-features

在 Google Places API 文档中,它指出可以使用多个关键字https://developers.google.com/places/training/additional-places-features

?keyword=theater+gym

?keyword=theater+gym

but this does not work in the JavaScript API. I tried:

但这在 JavaScript API 中不起作用。我试过:

function performSearch() {
  var request = {
    location: map.center,
    radius: '500',
    keyword: 'theater+gym+tacos',
    rankBy: 'distance'
  };
  service.radarSearch(request, callback);
}

...and does not return places for each keyword. Does anyone have an idea how to search multiple keywords?

...并且不会为每个关键字返回位置。有谁知道如何搜索多个关键字?

Note:I'm trying to search multiple individual keywords in one request not a phrase with spaces.

注意:我试图在一个请求中搜索多个单独的关键字,而不是带有空格的短语。

回答by geocodezip

It looks like the answer is "no" (at least at the present time, you could request an enhancement on the issue tracker.

看起来答案是否定的(至少目前,您可以请求增强问题跟踪器

A work around would be to send three separate queries, one for each keyword. Should be OK for 3 keywords, at some point you will run into the query rate limit.

一种解决方法是发送三个单独的查询,每个关键字一个。3 个关键字应该没问题,在某些时候你会遇到查询率限制。

  var request = {
    location: pyrmont,
    radius: 500,
    keyword: 'theater'
  };
  infowindow = new google.maps.InfoWindow();
  var service = new google.maps.places.PlacesService(map);
  service.nearbySearch(request, callback);
  var request2 = {
    location: pyrmont,
    radius: 500,
    keyword: 'gym'
  };
  var service2 = new google.maps.places.PlacesService(map);
  service2.nearbySearch(request2, callback);
  var request3 = {
    location: pyrmont,
    radius: 500,
    keyword: 'tacos'
  };
  var service3 = new google.maps.places.PlacesService(map);
  service3.nearbySearch(request2, callback);

proof of concept

概念证明

回答by netoale

Using Google place API, Make a boolean search seems to work like this :

使用 Google place API,进行布尔搜索的工作方式如下:

var request = {
            location: /*your location*/,
            radius: /*your radius*/,              
            keyword: "(cinema) OR (theater)"           
        };

you can use OR, AND but respect case!!

您可以使用 OR,AND 但要注意大小写!!

回答by Shovas

EDIT: This appeared to work initially but more results were not reliable and were not predictable. We ended up not being able to use the API in this way for our scenario.

编辑:这最初似乎有效,但更多结果不可靠且不可预测。我们最终无法在我们的场景中以这种方式使用 API。

I use the web service but I assume it should work with all API access points. It took me quite a number combinations to test but I eventually landed on realizing the API required parentheses AND quotes to get multi-word OR conditions to work.

我使用 Web 服务,但我认为它应该适用于所有 API 访问点。我花了很多组合来测试,但我最终意识到 API 需要括号和引号才能使多词 OR 条件起作用。

For example, in url param form:

例如,在 url 参数形式中:

keywords=("Place Name 1") OR ("PlaceName2") OR ("Place Name3")

关键字=(“地名1”)或(“地名2”)或(“地名3”)

回答by Markus G.

I had the same problem as I tried to figure out how to use multiple keywords with one request. At first the answer of @netoale helped me, but this is no longer possible. After some general problems with Google I asked in the support and one of the employees wrote me that it is possible to link several keywords with a simple "|".

我遇到了同样的问题,因为我试图弄清楚如何在一个请求中使用多个关键字。起初@netoale 的回答帮助了我,但这不再可能。在 Google 遇到一些一般性问题后,我向支持部门询问,其中一名员工写信给我说可以用简单的“|”链接多个关键字。

As an example:

举个例子:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=lat,lng&key=API_KEY&keyword=theater|castle|park&rankby=distance

Works for me now.

现在对我有用。

回答by power_scriptor

Did you try with type option. If using type you can get more than one place information

您是否尝试使用类型选项。如果使用类型,您可以获得多个地点信息

Please see the possible supported typesand RadarSearchRequeststry like this

请查看可能支持的类型RadarSearchRequests尝试这样

function performSearch() {
  var request = {
    location: map.center,
    radius: '500',
    types: ['movie_theater', 'gym'],
    rankBy: 'distance'
  };
  service.radarSearch(request, callback);
}

I don't know 'tacos' is which type. please supported type and give that 'tacos' type value.

我不知道“炸玉米饼”是哪种类型。请支持类型并给出“tacos”类型值。

Please let me know if you have any issues

如果您有任何问题,请告诉我

回答by Brett

I believe this is related to Google Maps API open issue 4845. Please star that issue to track progress.

我相信这与Google Maps API open issue 4845 有关。请为该问题加注星标以跟踪进度。