【问题标题】:geocoder.getLocations result in a vargeocoder.getLocations 产生一个 var
【发布时间】:2012-01-19 21:49:39
【问题描述】:

我浪费了很多时间,但我做不到。

感谢您的帮助。

如何在变量中获取逆地理定位的结果?

这是脚本:

geocoder = new GClientGeocoder();
geocoder.getLocations('43.3372814,(-1.79548311)', showAddress);

function showAddress(response) {

    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    return(place.address);
}

我已经尝试过:

var address = geocoder.getLocations('43.3372814,(-1.79548311)', showAddress);

但没有结果。

非常感谢您的帮助

【问题讨论】:

标签: javascript jquery


【解决方案1】:

http://code.google.com/apis/maps/documentation/javascript/v2/services.html 所述,第二个参数showAddress 是回调函数。因此,您必须执行以下操作:

geocoder.getLocations('43.3372814,(-1.79548311)', showAddress);

function showAddress(response) {
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}

【讨论】:

    猜你喜欢
    • 2014-04-09
    • 2023-03-06
    • 2018-09-08
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多