3

我目前有一个 PHP 脚本,它允许用户输入英国邮政编码。

我想知道是否有办法从他们输入的邮政编码中获取他们的地理位置。(通过谷歌的 API 什么的?)

我试过http://code.google.com/apis/maps/documentation/geocoding/index.html但它需要一个完整的地址,而我只有一个邮政编码。

帮助将不胜感激,谢谢 :) 彼得

4

5 回答 5

6

现在有一个免费的英国政府替代此处列出的其他选项。前往http://postcodes.io/查看 API 的详细信息和示例

于 2014-03-20T13:46:32.813 回答
5

这是一个可下载的所有英国邮政编码的经纬度数据库。

http://wikileaks.org/wiki/UK_government_database_of_all_1,841,177_post_codes_together_with_precise_geographic_coordinates_and_other_information,_8_Jul_2009

这是使用 Google Map API 对英国邮政编码进行地理编码的分步教程

http://www.tomanthony.co.uk/blog/geocoding-uk-postcodes-with-google-map-api/

于 2012-01-31T14:40:54.737 回答
3

Ordnance Survey 的 Open CodePoint 邮政编码数据集为您提供了所有英国大陆邮政编码的数据集

https://www.ordnancesurvey.co.uk/oswebsite/products/code-point-open/index.html

然后,您可以使用这样的库将这些转换为 WGS84 Lat/Long

http://www.jstott.me.uk/phpcoord/
于 2012-01-31T14:51:27.727 回答
2

您可以查看 Yahoo PlaceFinder API

这是一个示例 URL http://where.yahooapis.com/geocode?q=BL12DD&appid=[yourappidhere]

我过去用过这个,发现它有点准确。

文档:http: //developer.yahoo.com/geo/placefinder/

代码来了

<?php

    $data = fetchPage("http://where.yahooapis.com/geocode?q=BL12DD&appid=%5Byourappidhere%5D&flags=J");
    $yahooData = json_decode($data);

    echo '<pre>'.print_r($yahooData, true).'</pre>';

    echo '<br />Lat: ' . $yahooData->ResultSet->Results[0]->latitude;

     function fetchPage($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }

?>
于 2012-01-31T14:43:24.253 回答
0

虽然这已经得到解答:这里是一个简单 API 的链接,它允许通过单个或组合英国邮政编码(例如 ZE1 0AE)、部门、地区、城市和病房边界来获取用于 googlemaps 的 GeoJson。

https://www.mashape.com/vanitysoft/uk-boundaries-io

英国邮政查询

于 2015-08-22T22:23:19.043 回答