Google maps 谷歌地图>;位置搜索不定向

Google maps 谷歌地图>;位置搜索不定向,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我正在使用GoogleMapAPI(v3)创建一个美化的位置/商店查找。除了额外的位置搜索框(此处描述:)之外,一切正常 到目前为止,我已经成功地连接了搜索框(附件),但无法让地图自行定位,也无法在所选位置放置pin。显然,这与搜索框没有绑定到地图有关。。。我对这一切都不熟悉,所以这是我最好的猜测 任何帮助都将不胜感激 var map; function initialize() { var mapOptions = { zoom: 10,

我正在使用GoogleMapAPI(v3)创建一个美化的位置/商店查找。除了额外的位置搜索框(此处描述:)之外,一切正常

到目前为止,我已经成功地连接了搜索框(附件),但无法让地图自行定位,也无法在所选位置放置pin。显然,这与搜索框没有绑定到地图有关。。。我对这一切都不熟悉,所以这是我最好的猜测

任何帮助都将不胜感激

var map;
    function initialize() {
        var mapOptions = {
            zoom: 10,
            scrollwheel: false,
            center: new google.maps.LatLng(-33.9, 151.2)
        };
        map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions);

        setMarkers(map, beaches);

        infowindow = new google.maps.InfoWindow({
            content: "loading..."
        });


        // Create the search box and link it to the UI element.
  var input = /** @type {HTMLInputElement} */(
      document.getElementById('pac-input'));
  map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

  var searchBox = new google.maps.places.SearchBox(
    /** @type {HTMLInputElement} */(input));

  // [START region_getplaces]
  // Listen for the event fired when the user selects an item from the
  // pick list. Retrieve the matching places for that item.
  google.maps.event.addListener(searchBox, 'places_changed', function() {
    var places = searchBox.getPlaces();

    for (var i = 0, marker; marker = markers[i]; i++) {
      marker.setMap(null);
    }

    // For each place, get the icon, place name, and location.
    markers = [];
    var bounds = new google.maps.LatLngBounds();
    for (var i = 0, place; place = places[i]; i++) {
      var image = {
        url: place.icon,
        size: new google.maps.Size(71, 71),
        origin: new google.maps.Point(0, 0),
        anchor: new google.maps.Point(17, 34),
        scaledSize: new google.maps.Size(25, 25)
      };

      // Create a marker for each place.
      var marker = new google.maps.Marker({
        map: map,
        icon: image,
        title: place.name,
        position: place.geometry.location
      });

      markers.push(marker);

      bounds.extend(place.geometry.location);
    }

    map.fitBounds(bounds);
  });
  // [END region_getplaces]

  // Bias the SearchBox results towards places that are within the bounds of the
  // current map's viewport.
  google.maps.event.addListener(map, 'bounds_changed', function() {
    var bounds = map.getBounds();
    searchBox.setBounds(bounds);
  });

    }

    var beaches = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.923036, 151.259052, 5],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 1]
    ];

    function setMarkers(map, locations) {
        var image = {
            //url: '../assets/img/icon_mapPin.png',
            url: 'https://jira.appcelerator.org/secure/attachment/35489/map-pin.png',
            // This marker is 20 pixels wide by 32 pixels tall.
            size: new google.maps.Size(20, 29),
            // The origin for this image is 0,0.
            origin: new google.maps.Point(0,0),
            // The anchor for this image is the base of the flagpole at 0,32.
            anchor: new google.maps.Point(10, 29)
        };

        var shape = {
            coord: [1, 1, 1, 20, 29, 20, 29 , 1],
            type: 'poly'
        };
        for (var i = 0; i < locations.length; i++) {
            var beach = locations[i];
            var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
            var marker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                icon: image,
                shape: shape,
                title: beach[0],
                zIndex: beach[3],
                html: beach[0]
            });

            var contentString = '<div class="siteNotice">'+beach[1]+'</div>';

            google.maps.event.addListener(marker, "click", function () {
                infowindow.setContent(contentString);
                infowindow.open(map, this);
            });
        }
    }
    google.maps.event.addDomListener(window, 'load', initialize);
var映射;
函数初始化(){
变量映射选项={
缩放:10,
滚轮:错误,
中心:新google.maps.LatLng(-33.9151.2)
};
map=new google.maps.map(document.getElementById('map-canvas'),
地图选项);
设置标记(地图、海滩);
infowindow=新建google.maps.infowindow({
内容:“正在加载…”
});
//创建搜索框并将其链接到UI元素。
变量输入=/**@type{HTMLInputElement}*/(
document.getElementById('pac-input');
map.controls[google.maps.ControlPosition.TOP_LEFT].push(输入);
var searchBox=new google.maps.places.searchBox(
/**@type{HTMLInputElement}*/(输入));
//[开始区域\u getplaces]
//侦听当用户从中选择项目时激发的事件
//选择列表。检索该项目的匹配位置。
google.maps.event.addListener(搜索框,'places_changed',函数(){
var places=searchBox.getPlaces();
for(var i=0,marker;marker=markers[i];i++){
marker.setMap(空);
}
//对于每个位置,获取图标、地名和位置。
标记=[];
var bounds=new google.maps.LatLngBounds();
for(var i=0,place;place=places[i];i++){
变量图像={
url:place.icon,
大小:新谷歌地图大小(71,71),
来源:新google.maps.Point(0,0),
主播:新google.maps.Point(17,34),
scaledSize:new google.maps.Size(25,25)
};
//为每个地方创建一个标记。
var marker=new google.maps.marker({
地图:地图,
图标:图像,
标题:place.name,
位置:place.geometry.location
});
标记器。推(标记器);
扩展(place.geometry.location);
}
映射边界(bounds);
});
//[结束区域\u getplaces]
//将搜索框结果偏向在搜索范围内的位置
//当前地图的视口。
google.maps.event.addListener(映射'bounds_changed',函数(){
var bounds=map.getBounds();
searchBox.setBounds(边界);
});
}
var海滩=[
[Bondi Beach',-33.890542151.274856,4],
[Coogee Beach',-33.923036151.259052,5],
[Cronulla Beach',-34.028249151.157507,3],
[‘曼利海滩’,-33.80010128657071151.28747820854187,2],
[‘马鲁布拉海滩’,-33.950198151.259302,1]
];
功能设置标记(地图、位置){
变量图像={
//url:“../assets/img/icon_mapPin.png”,
网址:'https://jira.appcelerator.org/secure/attachment/35489/map-pin.png',
//此标记宽20像素,高32像素。
尺寸:新谷歌地图尺寸(20,29),
//此图像的原点为0,0。
来源:新google.maps.Point(0,0),
//此图像的锚定位于旗杆底部0,32处。
主持人:新谷歌地图点(10,29)
};
变量形状={
坐标:[1,1,1,20,29,20,29,1],
类型:“poly”
};
对于(变量i=0;i

报告了错误:

Uncaught ReferenceError: markers is not defined 
标记
数组应该像

var map;

function initialize() {
    var markers = [];
    ...