如何从英国邮政编码获取地理定位 [英] How to get geolocation from a UK postal code

查看:176
本文介绍了如何从英国邮政编码获取地理定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我想知道是否有办法从我的地理位置获得地理位置他们输入的邮编。 (通过谷歌的API或其他?)



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



帮助将不胜感激,谢谢:)
Peter

解决方案

您可以查看Yahoo PlaceFinder API



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



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

来源代码

 <?php 

$ data = fetc HPAGE( 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->结果[0] - >纬度;

函数fetchPage($ url){
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,TRUE);
$ result = curl_exec($ ch);
curl_close($ ch);
返回$ result;
}

?>


I have a PHP script at the moment which allows users to enter a UK postcode.

I was wondering if there was a way I could get their geolocation from the postcode they enter. (Through Google's API or something?)

I have tried http://code.google.com/apis/maps/documentation/geocoding/index.html but it requires a full address, whereas I only have a postcode.

Help would be appreciated, thanks :) Peter

解决方案

You could check out the Yahoo PlaceFinder API

Heres an example URL http://where.yahooapis.com/geocode?q=BL12DD&appid=[yourappidhere]

I have used this in the past and found it to be somewhat accurate.

Docs: http://developer.yahoo.com/geo/placefinder/

Heres come code

<?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;
    }

?>

这篇关于如何从英国邮政编码获取地理定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆