【发布时间】:2013-05-27 06:24:53
【问题描述】:
您好,我想知道 Geocoder 是否仍在工作?当我初始化新的 google.maps.geocoder(); 时,它似乎没有反应。我这里的目的是从经纬度中获取位置地址。
警报 A 和 B 正在工作。停在警报 C。
$('#btn').click(function initialize() {
alert("A");
var loc = {};
alert("B");
var geocoder = new google.maps.Geocoder();
alert("C");
if(google.loader.ClientLocation) {
alert("D");
loc.lat = google.loader.ClientLocation.latitude;
loc.lng = google.loader.ClientLocation.longitude;
var latlng = new google.maps.LatLng(loc.lat, loc.lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
alert(results[0]['formatted_address']);
};
});
}
});
【问题讨论】:
-
在
alert("C");之后使用alert(google.loader.ClientLocation);并说出你得到了什么。用google.loader.ClientLocation解释你,在调用这个函数之前你有纬度和经度吗? -
返回空值。为什么会这样?我已经包含了 jsapis.js 文件。
-
@Bryan Learn 我的回答可以从 Lat,Lng 获取地址吗?
-
@Lashmana Kumar,似乎无法加载 ClientLocation
标签: javascript jquery google-maps