TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Google Maps API to calculate distance between zips? (http://www.talkphp.com/general/3516-google-maps-api-calculate-distance-between-zips.html)

jcorradino 10-23-2008 06:39 PM

Google Maps API to calculate distance between zips? (solved)
 
Anyone know how to accomplish this feat?

I am trying to calculate the distance between one zip code and another (for a store locater). You can see it working here: Ligo Products - Quality Imported Furniture - Find Stores

I got it pretty much working, but I have two problems: the zip database I got from USPS does not seem to be very accurate, it (obviously) does not include Canadian postal codes, and for some reason, some zip codes either do not exist on the database, or the distance is not registered for some reason (making it seem as if that particular zip code is nowhere to be found).

I am using the following to find the distance in miles between one longitude/latitude and another

PHP Code:

$r 3963.1;
    
$pi 3.14159265358979323846;

    
$lat1 $lat1*($pi/180);
    
$lat2 $lat2*($pi/180);
    
$lon1 $lon1*($pi/180);
    
$lon2 $lon2*($pi/180);

    
$distance = ( acos cos $lat1 ) * cos $lon1 ) * cos $lat2 ) * cos $lon2 )  +  cos $lat1 ) * sin $lon1 ) * cos $lat2 ) * sin $lon2 ) + sin $lat1 ) * sin $lat2 ) ) * $r); 

For example, Biltrite should show up with a zip of 53220, but it does not show up until you change the distance selection to 40 miles.

Not only would I like to just implement the GMaps API, instead of digging through my code to find the culprit; I would also like to make the search much more accurate, which is not possible with the zips DB I have currently.

Thanks for the help!

jcorradino 10-26-2008 05:59 AM

so... no ideas?

jcorradino 10-30-2008 01:37 PM

found it - Creating a Store Locator with PHP, MySQL & Google Maps - Google Maps API - Google Code


All times are GMT. The time now is 11:40 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0