Using Google Map API to Get Latitude/Longitude

user-pic
Vote 0 Votes

Script Sample:
wget -qO- "http://maps.google.com/maps/geo?q=台中市中山路1號&output=csv"

Output:
200,8,24.1371957,120.6842909
(3rd column is latitude, 4th is longitude)

PHP Sample:
$ch = curl_init();
$address="台中市中山路1號";
curl_setopt($ch, CURLOPT_URL, "http://maps.google.com/maps/geo?q=$address&output=csv");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output=explode(',',curl_exec($ch));
curl_close($ch);
echo "Latitude: $output[2]
Longitude: $output[3]
";

Output:
Latitude: 24.1371957
Longitude: 120.6842909

ref. Google API 透過 HTTP 進行地理編碼

Leave a comment

About this Entry

This page contains a single entry by Pank published on March 27, 2010 5:22 AM.

UTF-8 CSV for Excel was the previous entry in this blog.

libnss-mysql - System-wide authentication using MySQL is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives