【发布时间】:2011-08-03 04:19:10
【问题描述】:
我正在尝试通过下一个示例http://jsbin.com/inepo3/7/edit 获取 Google Maps API 的 lng 和 lat 坐标。我期待一个“成功”弹出窗口,但它一直显示“错误”弹出窗口。 google maps-request 给出了正确的 json 反馈(由 firebug 检查)。
<script type="text/javascript">
$().ready(function() {
$.fn.getCoordinates=function(address){
$.ajax(
{
type : "GET",
url: "http://maps.google.com/maps/api/geocode/json",
dataType: "jsonp",
data: {
address: address,
sensor: "true"
},
success: function(data) {
set = data;
alert(set);
},
error : function() {
alert("Error.");
}
});
};
$().getCoordinates("Amsterdam, Netherlands");
});
</script>
有人知道如何解决这个问题吗?
问候, 圭多·莱蒙斯
编辑
我找到了一个使用结合在 jQuery 中的 Google Maps Javascript API 的 bether 解决方案:
<script type="text/javascript">
$().ready(function() {
var user1Location = "Amsterdam, Netherlands";
var geocoder = new google.maps.Geocoder();
//convert location into longitude and latitude
geocoder.geocode({
address: user1Location
}, function(locResult) {
console.log(locResult);
var lat1 = locResult[0].geometry.location.lat();
var lng1 = locResult[0].geometry.location.lng();
$("#testDiv").html("latitude:" + lat1 + "<p>longitude:" + lng1 + "</p>");
});
});
</script>
【问题讨论】:
-
google map api 的哪个版本?
-
我不是 shure,我猜是 v2(你能把用过的地图 url 转换成一个版本吗?)
-
我很确定它现在是 V3。
-
为什么不在 Google Maps JavaScript API 中使用地理编码器?
-
我同意 JSONP 的这种变化基本上是谷歌强迫人们使用谷歌地图地理编码器 api 的方式
标签: javascript jquery ajax google-maps google-maps-api-3