0

I'm quite new to using the google maps api, basically, what i'm trying to achieve is that i have a database that contains various addresses and information on a particular address,

the database is publicly released so would be occasionally updated by us, but the database doesn't contain a list of Longitude and latitudes, I can't quite work out how to run this database as is through the google maps api so we could output a map with each property pinned with some information. Can anyone shed any light or put me in the right direction? Cheers!

4

2 回答 2

1

从数据库中获取所有项目,并将它们循环到 URL 中,如下所示

http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Pennsylvania+Ave+Washington+DC&sensor=true

您将获得 XML 响应,对其进行解析并存储 lat/lng

请注意服务条款,但具体取决于您的请求数量。如果太多,请将它们分解并分块进行地理编码以避免达到限制。一旦你完成了一天的工作,这应该不是什么大不了的事。

这应该让你开始

$context  = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Pennsylvania+Ave+Washington+DC&sensor=true';

$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
print_r($xml);
于 2013-10-21T14:36:45.103 回答
0

我不确定您想要实现什么,但您必须使用地理编码将您的地址转换为纬度/经度。

然后,创建一个算法来获取所有 lat / lng 并将它们显示在地图上。如果您有任何问题,请尝试与我们联系

于 2013-10-21T14:33:22.537 回答