Longitude and Latitude

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Longitude and Latitude

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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"?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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! :)
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?"
Post Reply