Page 1 of 1
Longitude and Latitude
Posted: Wed Sep 21, 2005 2:50 pm
by Todd_Z
So basically, I want to incorporate google maps into my website. However, I need the longitude and latitude for the locations. The content is apartment and house locations, and they are stored in a database of street addresses, city, [MA], and zip code. Is there anyway to get the dimensions based on the street address? Maybe through google somehow? Thanks.
Basically, best case scenario, I have the user input their work address and a google map displays the closest apartments to the inputted address.
Posted: Wed Sep 21, 2005 3:15 pm
by feyd
Posted: Wed Sep 21, 2005 4:27 pm
by Todd_Z
Code: Select all
function getLongLat ( $location ) {
$page = file_get_contents( "http://geocoder.us/demo.cgi?address=".urlencode($location) );
preg_match( "#mapCenterLat = (-?[\.0-9]*), mapCenterLon = (-?[\.0-9]*),#", $page, $longLat );
return $longLat[1].",".$longLat[2];
}
That works, but its devilishly slow... any way to speed that sucker up? Any rss/text feeds for long/lat based on something like "123 Lane Road"?
Posted: Wed Sep 21, 2005 4:47 pm
by feyd
hmmmm... well, you could do some caching... use a quasi learning routine that can get a "close enough" match quickly. XMLHTTP may help smooth it out too... especially if you are using a "close enough" match, set the zoom out a ways, use XMLHTTP to get the exact coords and zoom in

It's a feature!

Posted: Wed Sep 21, 2005 4:51 pm
by Todd_Z
Feyd, you never cease to make me feel like a n00b.... thank you for it.
I don't understand however what you mean by a quasi-method.... I'm making this site for specifically the boston area, should I make a db with all the coors for the boston area by zip code and then use that?
Posted: Wed Sep 21, 2005 5:15 pm
by feyd
you could definitely start with a zip code, if they provided that. Since those coords are fairly known. Then, if you don't have the actual coords already, use the XMLHTTP idea. I'd log the addresses queried for.. and nightly or hourly batch out and cache the coords.. after a while you'll start to get pools, you can use that data to create the best guess... it can use a good deal of logic code, as you basically have to guess "Is this address near these others I've already collected?"