使用PHP从PIN码获取纬度和经度 [英] getting Latitude And Longitude From Pin Code Using PHP

查看:244
本文介绍了使用PHP从PIN码获取纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我想获得给定PIN码或邮政编码的经纬度。
如果我给 680721 作为密码或邮政编码,那么我想使用php代码来获取相应的经度和纬度。
我该怎么做?
如果这在PHP中是可行的?
我有php代码来获取给定地点的经度和纬度。

In my site i want to get the latitude and longitude of given pin code or postal code. If i give 680721 as pin code or postal code then i want to get its corresponding latitude and longitude using php code. How can i do this? If this is possible in PHP? I have php code to get latitude and longitude of given name of place.

$Url='http://maps.googleapis.com/maps/api/geocode/json?address='.$exp_pjctloc[$i].'&sensor=false';
if (!function_exists('curl_init')){
    die('Sorry cURL is not installed!');
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$search_data = json_decode($output);
$lat =  $search_data->results[0]->geometry->location->lat;
$lng =  $search_data->results[0]->geometry->location->lng;

但是,如何使用PIN码或邮政编码得到它?

But how can i get it by using pin code or postal code?

推荐答案

这对我很有用:

This worked for me:


$zip = 94043;
$site = file_get_contents('http://geocoder.ca/?postal='.$zip, false, NULL, 1000, 1000);
$goods = strstr($site, 'GPoint('); // cut off the first part up until 
$end = strpos($goods, ')'); // the ending parenthesis of the coordinate
$cords = substr($goods, 7, $end - 7); // returns string with only the 
$array = explode(', ',$cords); // convert string into array
echo "<pre>";
print_r($array); // output the array to verify

这篇关于使用PHP从PIN码获取纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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