从邮政编码中获取 LatLng - Google Maps API [英] Get LatLng from Zip Code - Google Maps API
问题描述
我想要的只是一些简单的示例代码,向我展示如何从输入的邮政编码或城市/州获取 latlng 元素.
All I want is some simple example code that shows me how to obtain a latlng element from an inputted zip code OR a city/state.
推荐答案
难道你不能直接调用下面的代码来替换 {zipcode} 为邮政编码或城市和州http://maps.googleapis.com/maps/api/geocode/json?地址={邮政编码}
Couldn't you just call the following replaceing the {zipcode} with the zip code or city and state http://maps.googleapis.com/maps/api/geocode/json?address={zipcode}
这是一个如何使用 JavaScript 进行地理编码的链接:地理编码漫游.如果您需要特定的经纬度数字,请调用 geometry.location.lat() 或 geometry.location.lng() (google.maps.LatLng 类的 API)
Here is a link with a How To Geocode using JavaScript: Geocode walk-thru. If you need the specific lat/lng numbers call geometry.location.lat() or geometry.location.lng() (API for google.maps.LatLng class)
获取纬度/经度的示例:
EXAMPLE to get lat/lng:
var lat = '';
var lng = '';
var address = {zipcode} or {city and state};
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
alert('Latitude: ' + lat + ' Logitude: ' + lng);
这篇关于从邮政编码中获取 LatLng - Google Maps API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!