gpt4 book ai didi

javascript - 无法读取属性 'getBounds' 。使用 addListenerOnce

转载 作者:行者123 更新时间:2023-12-03 09:55:58 29 4
gpt4 key购买 nike

下面是我的代码。我已添加 google.maps.event.addListenerOnce 但仍然收到此错误。不知道如何解决。谢谢。

“未捕获类型错误:无法读取未定义的属性“getBounds””

var map;
var service;

function handleSearchResults(results, status)
{
console.log(results);
}

function performSearch()
{
var request = {
bounds: map.getBounds(),
name: "McDonald's",
}
service.nearbySearch(request, handleSearchResults);
}

function initialise(location)
{
console.log(location);

var currentLocation = new google.maps.LatLng(location.coords.latitude, location.coords.longitude);

var mapOptions = {
center: currentLocation,
zoom: 12,
mapTypeID: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);

var marker = new google.maps.Marker({
position: currentLocation,
map: map
});

service = new google.maps.places.PlacesService(map);

google.maps.event.addListenerOnce(map, 'bounds_changed', performSearch);

}


$(document).ready(function()
{
navigator.geolocation.getCurrentPosition(initialise);
});

最佳答案

我对js不太熟悉,但是“initialize”函数中的“map”var似乎与全局变量不同(由两者前面的“var”关键字设置)。

关于javascript - 无法读取属性 'getBounds' 。使用 addListenerOnce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30736105/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com