Google Maps API v3找不到自己建议的位置(自动完成)

时间:2012-04-06 23:58:20

标签: google-maps-api-3

(Google Maps Developer Direction建议将其发布在此处)

我正在为我的网站使用Google Maps API v3,这是地址:http://goo.gl/YuyPo抱歉罗马尼亚语,但很容易看到搜索字段和地图,这是通用的:) (或者,您可以使用此处的官方Google Maps API v3自动完成示例:https://google-developers.appspot.com/maps/documentation/javascript/examples/places-autocomplete,它会做出同样的反应)

效果很好,但如果我搜索

Câmpulung Moldovenesc, Suceava, Romania

(完全相同)autocompetion工作,但如果我点击自动完成的值(上面的那个),它什么都不做。它应该去搜索&选定的地方。该位置有效,您可以在Google地图中找到它。

相同
Cîmpulung Moldovenesc, Suceava, Romania

(用罗马尼亚语Câmpulung是正确的,但直到大约15年前它才是Cîmpulung,并且在语言中间变成了â€

只有当我用i拼写(Cimpulung Moldovenesc)时,该搜索才能将我带到那个城镇。

最初,代码是来自该示例的代码我提供了链接(在我的示例中,代码被修改以满足我在搜索和自动完成之外的其他需求):

  

      Google Maps JavaScript API v3示例:展示自动填充功能       

<style type="text/css">
  body {
    font-family: sans-serif;
    font-size: 14px;
  }
  #map_canvas {
    height: 400px;
    width: 600px;
    margin-top: 0.6em;
  }
</style>

<script type="text/javascript">
  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-33.8688, 151.2195),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById('map_canvas'),
      mapOptions);

    var input = document.getElementById('searchTextField');
    var autocomplete = new google.maps.places.Autocomplete(input);

    autocomplete.bindTo('bounds', map);

    var infowindow = new google.maps.InfoWindow();
    var marker = new google.maps.Marker({
      map: map
    });

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      infowindow.close();
      var place = autocomplete.getPlace();
      if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
      } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17);  // Why 17? Because it looks good.
      }

      var image = new google.maps.MarkerImage(
          place.icon,
          new google.maps.Size(71, 71),
          new google.maps.Point(0, 0),
          new google.maps.Point(17, 34),
          new google.maps.Size(35, 35));
      marker.setIcon(image);
      marker.setPosition(place.geometry.location);

      var address = '';
      if (place.address_components) {
        address = [(place.address_components[0] &&
                    place.address_components[0].short_name || ''),
                   (place.address_components[1] &&
                    place.address_components[1].short_name || ''),
                   (place.address_components[2] &&
                    place.address_components[2].short_name || '')
                  ].join(' ');
      }

      infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
      infowindow.open(map, marker);
    });

    // Sets a listener on a radio button to change the filter type on Places
    // Autocomplete.
    function setupClickListener(id, types) {
      var radioButton = document.getElementById(id);
      google.maps.event.addDomListener(radioButton, 'click', function() {
        autocomplete.setTypes(types);
      });
    }

    setupClickListener('changetype-all', []);
    setupClickListener('changetype-establishment', ['establishment']);
    setupClickListener('changetype-geocode', ['geocode']);
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>   </head>   <body>
<div>
  <input id="searchTextField" type="text" size="50">
  <input type="radio" name="type" id="changetype-all" checked="checked">
  <label for="changetype-all">All</label>

  <input type="radio" name="type" id="changetype-establishment">
  <label for="changetype-establishment">Establishments</label>

  <input type="radio" name="type" id="changetype-geocode">
  <label for="changetype-geocode">Geocodes</lable>
</div>
<div id="map_canvas"></div>   </body> </html>

是否有解决方案或我应该以某种方式提交错误报告?非常感谢!

1 个答案:

答案 0 :(得分:0)

    var input = document.getElementById('searchTextFieldWhereMe');
    var autocomplete = new google.maps.places.Autocomplete(input,options);
    autocomplete.bindTo('bounds', this.map);

    var infowindow = new google.maps.InfoWindow();

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
           infowindow.close();
           var place = autocomplete.getPlace();
           if (place.geometry.viewport) {
              alfamap.map.fitBounds(place.geometry.viewport);
           } else {
             alfamap.map.setCenter(place.geometry.location);
             alfamap.map.setZoom(16);
           }

           alfamap.marker.setPosition(place.geometry.location);

           var address = '';
           if (place.address_components) {
             address = [(place.address_components[0] &&
                         place.address_components[0].short_name || ''),
                        (place.address_components[1] &&
                         place.address_components[1].short_name || ''),
                        (place.address_components[2] &&
                         place.address_components[2].short_name || '')
                       ].join(', ');
           }

           infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
           infowindow.open(alfamap.map, marker);
         });        

为我工作