0

好的,几乎解决了。我正在尝试使用来自附近搜索的地点属性(如下所示)

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

标记存储在一个数组中(如下)

    function createMarker(place) {
      var iconType = {};
      iconType['atm'] = "http://maps.google.com/mapfiles/ms/micons/dollar.png";
      iconType['bus_station'] = "http://maps.google.com/mapfiles/ms/micons/bus.png";
      //iconType['restaurant'] = "http://maps.google.com/mapfiles/ms/micons/restaurant.png";
      iconType['parking'] = "http://maps.google.com/mapfiles/ms/micons/parkinglot.png";
      var placeLoc = place.geometry.location;
      var marker = new google.maps.Marker({
      map : map,
      icon : iconType[place.types[0]],
      position : place.geometry.location,
      types : place.types
    });

    google.maps.event.addListener(marker, 'click', function() {
      infowindow.setContent(place.name);
      infowindow.open(map, this);
    });

    return marker;
  }

现在的问题是,下面的“if”语句与数组中的位置不匹配,我输入的字符串,我不确定语句本身是否错误,或者我是否没有正确检索 place.types 属性谷歌请求。

      function onRemoveBtn_Clicked() {
    var i;
    for (i = 0; i < markers.length; i++) {
      if (markers[i].get("types") != ATM) {
      markers[i].setMap(null);
    }
  }

到目前为止,我在这个问题上得到了很大的帮助,并感谢所有花时间帮助我的人,这是我最后一次打扰你了 :)

4

1 回答 1

1

如果将类型数组设置为标记,则 marker.get("types") 返回该数组。所以代码应该是这样的:

function onRemoveBtn_Clicked() {
  var i, j, isHit, types;
  for (i = 0; i < markers.length; i++) {
    types = markers[i].get("types");
    if (types) {
      isHit = false;
      for (j = 0; j < types.length; j++) {
        if (types[j] == "atm") {
          isHit = true;
          break;
        }
      }
      if (isHit) {
        markers[i].setMap(null);
      }
    }
  }
}
于 2012-11-20T05:27:27.560 回答