我的页面中有一个文本框,它获取位置名称和带有文本的按钮getLat&Long
。现在点击我的按钮我必须显示一个警报latitude
and longitude
文本框中的位置。有什么建议吗?
您可以使用谷歌地理编码服务 http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding in the 谷歌地图 API http://code.google.com/apis/maps/documentation/javascript/将您的位置名称转换为纬度和经度。所以你需要一些代码,例如:
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
// do something with the geocoded result
//
// results[0].geometry.location.latitude
// results[0].geometry.location.longitude
}
});
Update
您是否包含 v3 javascript API?
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=set_to_true_or_false">
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)