【发布时间】:2012-05-21 10:31:18
【问题描述】:
我想要做的是在地理编码器完成解析为 latlng 时添加一个标记...这是我的代码:
function parseLocation() {
var user1Location = "Mechelen, Belgium";
var geocoder = new google.maps.Geocoder();
//convert location into longitude and latitude
geocoder.geocode({
address: user1Location
}, function (locResult) {
lat1 = locResult[0].geometry.location.lat();
lng1 = locResult[0].geometry.location.lng();
if (status == google.maps.GeocoderStatus.OK) {
$('#map_canvas').bind('init', function () {
$('#map_canvas').gmap('addMarker', {
'position': lat1 + ',' + lng1
}).click(function () {
$('#map_canvas').gmap('openInfoWindow', {
'content': lat1 + ',' + lng1
}, this);
});
});
}
});
}
当我警告初始化函数中的变量未定义时,我知道此地理编码器是异步的,但我正在等待状态正常...知道我做错了什么吗?
【问题讨论】:
标签: javascript jquery google-maps geocoding