【发布时间】:2011-12-29 10:22:27
【问题描述】:
我最近开始查看 Google Maps API 以尝试在我的网站中尝试一些新的东西。我目前正在使用此代码:
<?php
$postcode = $_REQUEST['postcode'];
$url = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.$postcode.'&sensor=false';
$parsedXML = simplexml_load_file($url);
if($parsedXML->status != "OK") {
echo "There has been a problem: " . $parsedXML->status;
}
$myAddress = array();
foreach($parsedXML->result->address_component as $component) {
if(is_array($component->type)) $type = (string)$component->type[0];
else $type = (string)$component->type;
$myAddress[$type] = (string)$component->long_name;
}
header('Content-Type: application/json');
echo json_encode($myAddress);
?>
它只是使用我定义的邮政编码并搜索 Google 数据库,然后返回城镇、县等。
如果可能,我不仅想显示最近的城镇,还想显示半径 5-10 英里范围内的任何城镇。有人可以告诉我该怎么做吗?
感谢您的帮助
【问题讨论】:
-
在stackoverflow.com/search?q=radius+search+google+maps+php 有一些很有希望的问答 - 您检查了哪些,为什么它们没有帮助您解决问题?
-
我会看看这些,我在输入问题时确实查看了建议的帖子,但没有看到太多有用的东西。你知道我可以在哪里获得英国邮政编码数据库而无需支付皇家邮政愚蠢的钱吗?我看到一篇文章说 wikileaks 发布了它,但这是在 2009 年,所以我猜它不是完全最新的
-
不知道,抱歉。一个快速的谷歌提出了ordnancesurvey.co.uk/opendatadownload/products.html,但我不确定这些是否可以免费使用或有帮助。
标签: php google-maps google-maps-api-3