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

| 我正在使用SimpleGeo API,我需要通过邮政编码或城市名称来获取地点的纬度/经度。我知道在SO中有很多关于通过邮政编码获取坐标的问题,并且有很多不错的数据库。但是它们是否与SimpleGeo的数据紧密相关?我不想在SimpleGeo的数据库中拥有精确的城市名称/邮政编码,只是因为我的数据库与SG的数据库不同而一无所获。 另外,如果它提供了此类数据,我可以完全转向Foursquare API,但这是不太可取的。 因此,我的问题是: 我可以通过SimpleGeo(或至少Foursquare)通过邮政编码或城市名称获得纬度/经度吗? 如果没有,我可以使用其他数据库(例如MaxMind或Geonames)获得相同的结果吗?我是否应该关心数据库之间的差异?     
已邀请:
        是的,您可以使用SimpleGeo上下文API来执行此操作。 使用城市名称或邮政编码作为地址参数调用SimpleGeo上下文终结点,如下所示: http://api.simplegeo.com/1.0/context/address.json?address=98006 响应在返回的JSON Blob的\“ query \”部分中嵌入了纬度和经度:     {         \“查询\”:{           \“纬度”:40.745717,           “经度”:-73.988121           ...         },     ...     } 希望这可以帮助。 谢谢, 尼基尔     
        万一有帮助... 这是您使用Google \的地理编码器获取邮政编码的经/纬度的方法。假设您有一个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\"
          };
        }));
        }
      }
    }
}
谷歌的地理编码器可以对邮政编码进行地理编码,没问题。     

要回复问题请先登录注册