地点类型在Maps API上显示错误的地点类型

时间:2016-04-28 13:41:06

标签: google-maps google-places-api

我的地图api显示错误的地方类型,我无法弄清楚原因。请看下面的代码,我已经要求:

类型:['store','school','church','park','university','cafe','gym','bakery']

请在此处查看完整代码:

<script>

  var map;
  var infowindow;


  function initMap() {

    var image = 'http://www.vittoriagardens.com/wp-content/uploads/2016/04/pin.png';
    var myLatLng = {lat: 25.5244191, lng: -80.4063932};

    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      scrollwheel: false,
      center: myLatLng
    });

    var principal = new google.maps.Marker({
      position: myLatLng,
      map: map,
      title: 'Vittoria',
      icon: image

    });

    infowindow = new google.maps.InfoWindow();

    /*lojas*/
    var placestore = new google.maps.places.PlacesService(map);
    placestore.nearbySearch({
      location: myLatLng,
      radius: 2500,
      type: ['store', 'school', 'church', 'park', 'university', 'cafe', 'gym', 'bakery']
    }, callback);

  }

  function callback(results, status) {
    if (status === google.maps.places.PlacesServiceStatus.OK) {
      for (var i = 0; i < results.length; i++) {
        createMarker(results[i]);
      }
    }
  }

  function createMarker(place) {
    var placeLoc = place.geometry.location;

    var iconType = {};
    iconType['school'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_school.png";
    iconType['church'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_church.png";
    iconType['park'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_park.png";
    iconType['university'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_school.png";
    iconType['store'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_shopping_mall.png";
    iconType['cafe'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_bakery.png";
    iconType['bakery'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_bakery.png";
    iconType['gym'] = "http://www.vittoriagardens.com/wp-content/uploads/2016/04/categoria_gym.png";

    var marker = new google.maps.Marker({
      map: map,
      icon: iconType[place.types[0]],
      position: place.geometry.location
    });

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

</script>

我不知道为什么,但在地图上你可以看到:Vittoria Gardens或者在下面的图片中Print of the map on the website,例如,它显示的是墨西哥餐厅和UPS客户服务中心,我并没有要求这类地方。

有谁知道为什么会这样? 谢谢

1 个答案:

答案 0 :(得分:0)

来自the documentation

  

警告:文本搜索请求中类型的实现正在发生变化。 types参数自2016年2月16日起不再使用,替换为每个搜索请求仅支持一种类型的新类型参数。此外,将不再支持建立,place_of_worship,food,health,general_contractor和财务类型作为搜索参数(但是这些类型仍可能在搜索结果中返回)。使用已弃用功能的请求将在2017年2月16日之前得到支持,之后所有文本搜索都必须使用新实现。

虽然上面的文字明确指出“文字搜索”,但它也适用于NearbySearch

这不起作用:

type: ['store', 'school', 'church', 'park', 'university', 'cafe', 'gym', 'bakery']