1

(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

(完全像这样)自动竞争有效,但如果我点击自动完成的值(上面的那个),它什么也不做。它应该去搜索和选择的地方。该位置是有效的,例如,您可以在 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>

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

4

1 回答 1

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);
         });        

为我工作

于 2012-06-01T11:53:20.543 回答