如何把邮编转换为经度和纬度?

问题描述:

我想通过邮政编码的帮助来查找地点的经纬度。 任何人都可以告诉我该怎么做?如何把邮编转换为经度和纬度?

一个在actionscript中的例子对我来说非常有帮助。因为我在Flex中制作项目。

问候 Zee的

+2

你在说什么是反向地理编码。您可以查询免费的webservice GeoNames.org获取邮政编码的经纬度 – 2009-09-18 22:43:39

你有机会获得长/ LAT数据库?如果没有,我相信你可以使用谷歌地图API来做这个查询。

哦..我只注意到克里斯的回答。我对geonames不熟悉。您可能还需要熟悉“http://freegeographytools.com/”,该工具为各种项目提供了大量的地理编码,gps等资源。

啊......我刚刚访问了Eric的博客文章。这是极好的!我将在未来的项目中详细介绍谷歌。

如果您正在寻找按需地理编码,请使用Google。他们提供了一个简单的pox web服务版本。

我写了一篇关于这段时间的博客。查看this link了解使用此简单地理编码的分步说明。

干杯, 埃里克

several places to get zip code databases,以多种格式。将其加载到您最喜爱的RDBMS中,然后查询。

或者,您可以使用其他人的Web服务为您查找值。其他答案已发布可能的Web服务;此外,geocoder.us现在似乎也支持ZIP code lookup

我得到了我的解决,你也可以

function getLatLong($code) { 
    $mapsApiKey = 'ABQIAAAAsV7S85DtCo0H9T4zv19FoRTdT40ApbWAnDYRE0-JyP5I6Ha9-xT9G5hCQO5UtOKSH5M3qhp5OXiWaA'; 
    $query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey; 
    $data = file_get_contents($query); 
    // if data returned 
    if($data) { 
    // convert into readable format 
    $data = json_decode($data); 
    $long = $data->Placemark[0]->Point->coordinates[0]; 
    $lat = $data->Placemark[0]->Point->coordinates[1]; 
    return array('Latitude'=>$lat, 'Longitude'=>$long); 
    } else { 
    return false; 
    } 
} 

目前人们使用最新的谷歌地图API(v3)而这更好的解决方案。以下是来自multiplesources的稍微修改的示例。我必须给予他们大部分的信贷。它是PHP,使用cURL从Google检索数据,但您也可以使用Ajax。

function address_lookup($string){ 

    $string = str_replace (" ", "+", urlencode($string)); 
    $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false"; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $details_url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $response = json_decode(curl_exec($ch), true); 

    // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST 
    if ($response['status'] != 'OK') { 
    return null; 
    } 

    $geometry = $response['results'][0]['geometry']['location']; 

    $array = array(
     'lat'  => $geometry['lat'], 
     'lng'  => $geometry['lng'], 
     'state' => $response['results'][0]['address_components'][3]['short_name'], 
     'address' => $response['results'][0]['formatted_address'] 
    ); 

    return $array; 

} 

$zip= '01742'; 

$array = address_lookup($zip); 
print_r($array); 

最简单的方法就是使用GoogleMap Api。假设你在一个可变的$ zipcode中有一个邮政编码。

$latlongUrl = 'http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:'.$zipcode; 

    $data = file_get_contents($latlongUrl); // you will get string data 
    $data = (json_decode($data)); // convert it into object with json_decode 
    $location = ($data->results[0]->geometry->location); // get location object 

$ location是具有经度和纬度值的对象。