cbeverly
asked on
Google geocoding latitude longitude problem
I am trying to populate our database full of addresses with their corresponding latitude and longitude so we can encorporate the Google map API into our web site. The problem is when we use googles geocoding we are getting slightly different latitude and longitudes than what the public Google maps shows:
Example: If you type in this address into the public Google Maps:
9000 Plymouth Avenue North, Golden Valley, Minnesota
Googles public interface gives Lat=45.002377 Long= -93.38748
But when you use Googles geocoding (using http://maps.google.com/maps/geo?q=address) with the same address it gives you: Lat= 44.993989 Long= -93.392879
Displaying these coordinates on a map gives you slightly different locations.
How can we get accurate latitude and longitudes for our addresses?
Thank you for your help.
Example: If you type in this address into the public Google Maps:
9000 Plymouth Avenue North, Golden Valley, Minnesota
Googles public interface gives Lat=45.002377 Long= -93.38748
But when you use Googles geocoding (using http://maps.google.com/maps/geo?q=address) with the same address it gives you: Lat= 44.993989 Long= -93.392879
Displaying these coordinates on a map gives you slightly different locations.
How can we get accurate latitude and longitudes for our addresses?
Thank you for your help.
is the formatting of the address correct eg is it not finding "9000 Plymouth Avenue North, Golden Valley, Minnesota" so its going onto "Plymouth Avenue North, Golden Valley, Minnesota" or even "Golden Valley, Minnesota"
ASKER
The format of the address is correct. It maps it to almost the correct spot, but not quite.
which one is correct?
ASKER
The google public interface gives the correct lat/long which is Lat=45.002377 Long= -93.38748
The short answer may be, "You can't" -- but I would bring this up in a Google forum. I've written a script to test your issue - it is in the code snippet. From the output, it looks like you are within 500 feet of the "exact" location when calling the geocoder.
Here is the URL of the Google public interface for printing the map:
http://www.google.com/maps?f=q&hl=en&geocode=&q=9000+Plymouth+Avenue+North,+Golden+Valley,+Minnesota&sll=44.993989,-93.392879&sspn=0.044431,0.113554&ie=UTF8&z=16&iwloc=addr&pw=2
I tried tinkering with the SSPN args, but that didn't seem to help much.
Your accuracy level is '8' from the geocoder. I think a 9 is considered the best.
http://code.google.com/apis/maps/documentation/reference.html#GGeoAddressAccuracy
But you may not have to make do with only what Google is able to tell you....
Here is the URL of the Google public interface for printing the map:
http://www.google.com/maps?f=q&hl=en&geocode=&q=9000+Plymouth+Avenue+North,+Golden+Valley,+Minnesota&sll=44.993989,-93.392879&sspn=0.044431,0.113554&ie=UTF8&z=16&iwloc=addr&pw=2
I tried tinkering with the SSPN args, but that didn't seem to help much.
Your accuracy level is '8' from the geocoder. I think a 9 is considered the best.
http://code.google.com/apis/maps/documentation/reference.html#GGeoAddressAccuracy
But you may not have to make do with only what Google is able to tell you....
<?php // RAY_google_geocoder.php
// GET GOOGLE API
require_once('_config.php');
// SET LOCATION
$loc = '9000 Plymouth Avenue North, Golden Valley, Minnesota';
$addr = urlencode($loc);
// GOOGLE CALL - ASK FOR CSV DATA
unset ($g_lat, $g_lon, $g_buf);
$g_AOK = FALSE;
$google_url = "http://maps.google.com/maps/geo?q=" . $addr . "&output=csv&key=$google_API";
if ($fp = fopen($google_url, 'r')) {
while (!feof($fp)) { $g_buf .= fgets($fp); }
fclose($fp);
}
// EXTRACT INFORMATION FROM THE CSV STRING
if ($g_buf != '') { // NOT EMPTY, WE GOT DATA
$x = explode(',', $g_buf);
if ($x[0] == 200) { // RETURN CODE OK
if ($x[1] >= 5) { // ACCURACY VALUE AT LEAST 5 ('ZIP CODE' PROXIMITY) HIGHER IS BETTER
$g_lat = $x[2];
$g_lon = $x[3];
$g_AOK = $x[1];
}
}
}
// SHOW THE GOOGLE ADDRESS LOOKUP
echo "<a target=\"loc_G\" href=\"http://www.google.com/maps?f=q&hl=en&geocode=&q=$addr&ie=UTF8&z=16&iwloc=addr&pw=2\">$loc</a>\n";
echo "<br />\n";
// LINK TO GOOGLE MAP FOR THE GOOGLE - CODED LAT/LON PAIR
if ($g_AOK) {
echo "<a target=\"geo_G\" href=\"http://www.google.com/maps?f=q&hl=en&geocode=&q=" . $g_lat .','. $g_lon . "&ie=UTF8&z=16&iwloc=addr\">G $g_lat $g_lon</a> $g_AOK \n";
} else {
var_dump($g_buf);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! This was very helpful.