SimpleGeo 是否提供邮政编码到纬度/经度映射?

发布于 2024-11-10 16:19:01 字数 673 浏览 4 评论 0原文

我正在使用 SimpleGeo API,我需要获取地点的纬度/邮政编码或城市名称的经度。我知道 SO 中有很多关于通过邮政编码获取坐标的问题,并且有很多不错的数据库。但它们是否与 SimpleGeo 的数据密切相关?我不希望 SimpleGeo 数据库中存在精确的城市名称/邮政编码,仅仅因为我的数据库与 SG 的数据库不同而无济于事。

或者,我可以完全转向 Foursquare API(如果它提供此类数据),但是这是不太优选的。

所以,我的问题是:

  1. 我可以通过 SimpleGeo(或至少 Foursquare)通过邮政编码或城市名称获取纬度/经度吗?
  2. 如果没有,我可以使用其他数据库(例如 MaxMindGeonames) 得到相同的结果?我应该关心数据库之间的差异吗?

I'm working with SimpleGeo API and I need to get place's latitude/longitude by ZIP code or city name. I know there is a plenty of questions in SO about getting coordinates by ZIP code, and there are many nice databases for it. But are they something that correlates closely with SimpleGeo's data? I don't want, having a precise city name/ZIP code that exists in SimpleGeo's database, to get to nowhere just because my database differs from SG's one.

Alternatively, I can move completely to Foursquare API, if it provides such data, but this is less preferable.

So, my questions are:

  1. Can I get latitude/longitude by ZIP code or city name through SimpleGeo (or at least Foursquare)?
  2. If not, can I use other databases (e.g. MaxMind or Geonames) to get same results? Should I care about differences between databases at all?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

韵柒 2024-11-17 16:19:01

是的,您可以使用 SimpleGeo Context API 来执行此操作。
使用城市名称或邮政编码作为地址参数来调用 SimpleGeo 上下文端点,如下所示:
http://api.simplegeo.com/1.0/context/address.json ?address=98006

响应将纬度和经度嵌入到返回的 JSON blob 的“查询”部分中:
{
“询问”:{
“纬度”:40.745717,
“经度”:-73.988121
...
},
...
希望

这有帮助。

谢谢,
-尼基尔

Yes, you can use the SimpleGeo Context APIs to do this.
Call the SimpleGeo context endpoint with the city name or zip code as the address parameter like this:
http://api.simplegeo.com/1.0/context/address.json?address=98006

The response has the latitude and longitude embedded in the "query" part of the JSON blob returned:
{
"query":{
"latitude":40.745717,
"longitude":-73.988121
...
},
...
}

Hope this helps.

Thanks,
-Nikhil

夜空下最亮的亮点 2024-11-17 16:19:01

万一有帮助...
以下是如何使用谷歌的地理编码器获取邮政编码的纬度/经度。假设您有一个 ID 为“location”的 HTML 输入(使用 jqueryui 自动完成小部件):

// insert a div for autocomplete results
$("#location").after('<div id="location-results"></div>');

$("#location").autocomplete({
    appendTo:$("#location-results"),
    minLength: 3,
    open: acOpen,
    select: acSelect,
    close: acClose,
    source: acSource
});

function acOpen(event, ui){
// no op, but put code here to handle results list open if you need it
}

function acSelect(event, ui){
    // fired when user selects a result from the autocomplete list
    // assuming you are using the json2.js library for json parsing/decoding
    alert(JSON.stringify(ui.item));
    // the lat/lng is in ui.item.latLng.lat() and ui.item.latLng.lng()
    // ui.item.latLng is of type google.maps.LatLng (see v3 api)
}

function function acClose(event, ui){
// no op, but put code here to handle results list close if you need it
}

function acSource(request, response) {
    // implements the autocomplete source for the widget
    geocoder.geocode( {'address': request.term }, function(results, status) {
        if(undefined!==results){
            var postal_code='';
            var city = ''; 
            var state = '';
            var country = '';
            response($.map(results, function(item) {
              $.each(item.address_components, function(item_i, item_v){
                $.each(item_v.types, function(type_i, type_v){
                  switch(type_v){
                    case "locality": case "administrative_area_level_3":
                      city = item_v.long_name;
                    break;
                    case "administrative_area_level_2":
                    break;
                    case "street_number":
                    break;
                    case "route":
                    break;
                    case "administrative_area_level_1":
                  state = item_v.long_name;
                break;
                case "country":
                  country = item_v.long_name;
                break;
                case "postal_code":
                  postal_code = item_v.long_name;
                break;
              }
        });
          });
              // the object that gets returned and is ui.item on select event
          return {
            label   : item.formatted_address,
            value   : item.formatted_address,
            latLng  : item.geometry.location,
            country     : country, 
                state       : state, 
                city        : city,  
                postal_code : postal_code,
            source  : "google"
          };
        }));
        }
      }
    }
}

谷歌的地理编码器可以对邮政编码进行地理编码,没问题。

In case it helps...
Here's how you can use google's geocoder to get the lat/lng for zipcode. Say you have an HTML input with the id 'location' (uses the jqueryui autocomplete widget):

// insert a div for autocomplete results
$("#location").after('<div id="location-results"></div>');

$("#location").autocomplete({
    appendTo:$("#location-results"),
    minLength: 3,
    open: acOpen,
    select: acSelect,
    close: acClose,
    source: acSource
});

function acOpen(event, ui){
// no op, but put code here to handle results list open if you need it
}

function acSelect(event, ui){
    // fired when user selects a result from the autocomplete list
    // assuming you are using the json2.js library for json parsing/decoding
    alert(JSON.stringify(ui.item));
    // the lat/lng is in ui.item.latLng.lat() and ui.item.latLng.lng()
    // ui.item.latLng is of type google.maps.LatLng (see v3 api)
}

function function acClose(event, ui){
// no op, but put code here to handle results list close if you need it
}

function acSource(request, response) {
    // implements the autocomplete source for the widget
    geocoder.geocode( {'address': request.term }, function(results, status) {
        if(undefined!==results){
            var postal_code='';
            var city = ''; 
            var state = '';
            var country = '';
            response($.map(results, function(item) {
              $.each(item.address_components, function(item_i, item_v){
                $.each(item_v.types, function(type_i, type_v){
                  switch(type_v){
                    case "locality": case "administrative_area_level_3":
                      city = item_v.long_name;
                    break;
                    case "administrative_area_level_2":
                    break;
                    case "street_number":
                    break;
                    case "route":
                    break;
                    case "administrative_area_level_1":
                  state = item_v.long_name;
                break;
                case "country":
                  country = item_v.long_name;
                break;
                case "postal_code":
                  postal_code = item_v.long_name;
                break;
              }
        });
          });
              // the object that gets returned and is ui.item on select event
          return {
            label   : item.formatted_address,
            value   : item.formatted_address,
            latLng  : item.geometry.location,
            country     : country, 
                state       : state, 
                city        : city,  
                postal_code : postal_code,
            source  : "google"
          };
        }));
        }
      }
    }
}

google's geocoder can geocode zipcodes, no problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文