为什么我会收到“map.set_center 不是函数”?
这段代码一直有效,直到我昨晚更新为止。
该代码在我的本地主机上完美运行,但在我的测试服务器上出现错误。错误消息(来自 Firebug)是“map.set_center 不是函数”
。
那么为什么这在我的服务器上不再起作用了?
function googleMapInit()
{
if (jQuery('#map_canvas').length > 0) {
var currentLocation = jQuery('#geomap_ddlCity :selected').text() + ', ' + jQuery('#geomap_ddlCountry :selected').text();
var options = {zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP }
var map = new google.maps.Map(document.getElementById("map_canvas"), options);
var geocoder = new google.maps.Geocoder();
//Center map for current selected city
geocoder.geocode(
{
address: currentLocation}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK && results.length) {
alert(results[0].geometry.location);
map.set_center(results[0].geometry.location);
} else
{
var oslo = new google.maps.LatLng(59.9167, 10.75);
map.set_center(oslo);
}
}
);
}
}
This code have been working until I updated last night.
The code works perfectly on my localhost, but I get an error on my test server. The error message (from Firebug) is "map.set_center is not a function"
.
So why is this not working on my server any more?
function googleMapInit()
{
if (jQuery('#map_canvas').length > 0) {
var currentLocation = jQuery('#geomap_ddlCity :selected').text() + ', ' + jQuery('#geomap_ddlCountry :selected').text();
var options = {zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP }
var map = new google.maps.Map(document.getElementById("map_canvas"), options);
var geocoder = new google.maps.Geocoder();
//Center map for current selected city
geocoder.geocode(
{
address: currentLocation}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK && results.length) {
alert(results[0].geometry.location);
map.set_center(results[0].geometry.location);
} else
{
var oslo = new google.maps.LatLng(59.9167, 10.75);
map.set_center(oslo);
}
}
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
地图类;您可能应该使用
setCenter
来代替。It seems there is no
set_center
method in the Map class ; you should probably usesetCenter
, instead.