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 応答を取得して解析し、緯度/経度を保存します。

リクエストの数にもよりますが、利用規約に注意してください。数が多すぎる場合は、それらを分割し、チャンクにジオコーディングして、制限に達しないようにします。一日の予定が立てば、大したことではありません。

これで始められるはずです

$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

何を達成したいのか正確にはわかりませんが、ジオコーディングを使用して住所を緯度/経度に変換する必要があります。

次に、すべての緯度/経度を取得して地図上に表示するアルゴリズムを作成します。ご不明な点がございましたら、お気軽にお問い合わせください。

于 2013-10-21T14:33:22.537 に答える