簡體   English   中英

如何將郵政編碼轉換為GeoJSON

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM