【问题标题】:How to convert zip code into GeoJSON如何将邮政编码转换为 GeoJSON
【发布时间】:2017-04-24 05:40:21
【问题描述】:

我有一组包含他们邮政编码的用户,我想根据他们在 Google 地图上的邮政编码显示他们的位置,但我无法将我的邮政编码转换为 GeoJSON 格式。帮帮我

【问题讨论】:

  • 你做了什么?给我们看一些代码。

标签: javascript jquery ruby-on-rails google-maps


【解决方案1】:

从我查找的内容来看,GeoJSON 使用纬度和经度对吗?

如果是这种情况,您可以使用另一个 api,根据您在其查询中输入的邮政编码告诉您纬度和经度。

使用谷歌 api:

http://maps.googleapis.com/maps/api/geocode/json?address={邮编}

从上面的 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);


});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 2019-01-22
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    相关资源
    最近更新 更多