【发布时间】:2012-07-08 10:20:51
【问题描述】:
好吧,我是从我找到的一个例子中提取的,但是我的大脑被热炸了,无论如何 google api 总是对我做一些事情
function codeLatLng(lat, lng)
{
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
//console.log(results)
if(results[1])
{
//formatted address
//alert(results[0].formatted_address)
//find country name
$('#geolocation_latlng').html(latlng);
for(var i=0; i<results[0].address_components.length; i++)
{
for(var b=0;b<results[0].address_components[i].types.length;b++)
{
//there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
if(results[0].address_components[i].types[b] == "administrative_area_level_1")
{
//this is the object you are looking for
city=results[0].address_components[i];
break;
}
}
}
//city data
//alert(city.short_name + " " + city.long_name)
}
else
{
alert("Could not Determin Location");
}
}
else
{
alert("Location dection failed: " + status);
}
});
}
可以安全地假设 lat 和 lon 已经通过并且我得到了结果,我注释掉了一个关于 formated_address 的警报,我想要做的是弄清楚我可以如何获取邮政编码、州、城市该格式化地址并将其显示在屏幕上。但就像我说的,我现在炸了,我在敲钟,所以我需要一些帮助来启动我。
【问题讨论】:
-
您与哪些国家/地区合作?
-
现在只是美国,虽然让它足够开放以便将来扩展到其他国家会很好,因为我确实打算让其他国家迟早访问该网站
标签: javascript jquery google-maps geolocation