【问题标题】:Google Places API - Using multiple place types from a checkboxGoogle Places API - 使用复选框中的多种地点类型
【发布时间】:2016-10-07 08:46:56
【问题描述】:

更新: 我正在尝试以数组形式发送具有多种类型的 Google Places API 请求。但是,我无法传递带有从复选框值添加的位置列表的数组变量。任何帮助将不胜感激。

这行得通:

var poi = new google.maps.LatLng(lt,lg);
var gplaces = ['shopping_mall','bus_station'];

var request = {
    location: poi,
    radius: '500',
    types: gplaces
  };

但不是这个:

var poi = new google.maps.LatLng(lt,lg);
var gplaces = []

$('#chklist:checked').each(function() {
   gplaces.push($(this).val());
 });

var request = {
    location: poi,
    radius: '500',
    types: gplaces
  };

在第二种情况下,API 将返回一个默认的地点列表(好像我根本没有传递任何类型)。

我尝试了一个 console.log(gplaces),它包含 ['shopping_mall','bus_station']。

我还检查了 console.log(request),我可以在请求中看到列表的各个元素。

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 你能粘贴更多代码吗?对我来说很好用
  • @weigreen 我现在已经更新了这个问题。请检查。
  • 你能做一个小提琴吗?

标签: google-maps google-places-api


【解决方案1】:

我尝试了你的两个代码,它对我有用。也许问题不存在。尝试再次检查以确认错误所在。

这是我测试的示例。

infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
var gplaces = ['shopping_mall','bus_station']
service.nearbySearch({
location: pyrmont,
radius: '500',
types: gplaces
}, callback);

在这里他们都在工作。

infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: pyrmont,
radius: 500,
types: ['shopping_mall','bus_station']
}, callback);

此外,有关其他信息,types 参数自 2016 年 2 月 16 日起已弃用,取而代之的是新的类型参数,该参数仅支持每个搜索请求一个 type。 (但是,这些类型可能仍会在搜索结果中返回)。 2017 年 2 月 16 日之前将支持使用已弃用功能的请求,此后所有文本搜索都必须使用新实现。

请注意这个deprecation announcement

【讨论】:

  • 对不起,你是对的。传递数组变量确实可以正常工作。但是,就我而言,数组 (gplaces) 从复选框中获取值。我现在已经更新了这个问题。请再看一遍。
猜你喜欢
  • 2015-10-15
  • 1970-01-01
  • 2015-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-25
  • 1970-01-01
  • 2016-11-26
相关资源
最近更新 更多