[英]How to convert zip code into GeoJSON
我有一组包含邮政编码的用户,我想根据他们在Google Maps上的邮政编码显示位置,但是我无法将其邮政编码转换为GeoJSON格式。 帮我
根据我的查找,GeoJSON使用纬度和经度对吗?
如果是这种情况,您可以使用另一个api,根据您在查询中输入的邮政编码来告诉您纬度和经度。
使用Google API:
http://maps.googleapis.com/maps/api/geocode/json?address= {zipcode}
从上面的JSON中提取纬度/经度坐标值:
var zipCode; //from your array of users
$.getJSON("http://maps.googleapis.com/maps/api/geocode/json?address=" + zipCode, function (json){
var latitude = json.results[0].geometry.location.lat;
var longitude = json.results[0].geometry.location.lng;
//Handle your geoJSON here, I'm just guessing on this part I don't know geoJSON
var geojsonFeature =
{
"type": "Feature",
"properties":
{
"name": "",
"amenity": "",
"popupContent": ""
},
"geometry":
{
"type": "Point",
"coordinates": [latitude, longitude]
}
};
L.geoJSON(geojsonFeature).addTo(map);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.