Javascript 尝试在谷歌地图上设置纬度和经度时出现灰色框

Javascript 尝试在谷歌地图上设置纬度和经度时出现灰色框,javascript,jquery,google-maps,Javascript,Jquery,Google Maps,将纬度和经度设置为名为“myLatLng”的变量后,我的Google地图对象显示为灰色框。我尝试设置纬度和经度的独立变量,当时效果很好,但据我所知,使用geometry.location应该可以工作,如下代码所示。我做错了什么 $(document).ready(function(){ geocoder = new google.maps.Geocoder(); geocoder.geocode({address: "Windsor, ON"}, function

将纬度和经度设置为名为“myLatLng”的变量后,我的Google地图对象显示为灰色框。我尝试设置纬度和经度的独立变量,当时效果很好,但据我所知,使用geometry.location应该可以工作,如下代码所示。我做错了什么

$(document).ready(function(){
        geocoder = new google.maps.Geocoder();
        geocoder.geocode({address: "Windsor, ON"}, function(results) {
            var myLatLng = results[0].geometry.location;
            var mapOptions = {
            zoom: 8, 
            center: new google.maps.LatLng(myLatLng), 
            mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            var map = new google.maps.Map($("#map").get(0), mapOptions);
        });
    });

结果[0]。geometry.location已经是google.maps.LatLng。这不起作用(google.maps.LatLng构造函数需要2个数字作为参数):

按原样使用即可:

center: myLatLng
工作代码段:

$(文档).ready(函数(){
geocoder=新的google.maps.geocoder();
geocoder.geocode({地址:“Windsor,ON”},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
var mylatng=results[0]。geometry.location;
变量映射选项={
缩放:8,
中心:myLatLng,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
var map=new google.maps.map($(“#map”).get(0),mapOptions);
}否则{
警报('地理编码因以下原因未成功:'+状态);
}
});
});

center: myLatLng