我想得到一个用纬度和经度定义的地方周围的城市列表,这是我使用的简单代码:
JSON.stringify = JSON.stringify || function (obj) {
var t = typeof (obj);
alert(t);
if (t != "object" || obj === null) {
if (t == "string") obj = '"'+obj+'"';
return String(obj);
} else {
var n, v, json = [], arr = (obj && obj.constructor == Array);
for (n in obj) {
v = obj[n]; t = typeof(v);
if (t == "string") v = '"'+v+'"';
else if (t == "object" && v !== null) v = JSON.stringify(v);
json.push((arr ? "" : '"' + n + '":') + String(v));
}
return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
}
}
function insertReply(content) {
var JSONString = JSON.stringify(content);
document.body.innerHTML += JSONString;
alert(JSONString);
}
var script = document.createElement('script');
var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false&callback=insertReply";
script.src = (url);
document.body.appendChild(script);
但似乎谷歌地图不支持回调选项(...&callback=insertReply)是解决方案吗?先感谢您..