TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-23-2008, 06:39 PM   #1 (permalink)
The Contributor
 
jcorradino's Avatar
 
Join Date: Sep 2008
Posts: 36
Thanks: 2
jcorradino is on a distinguished road
Default 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!
__________________
Jason Corradino
Applications Developer, Interactive Support - Tribune Technology
J2EE Development, Script Tinkering - Develop, Support, and Maintain Tribune websites.

Last edited by jcorradino : 10-30-2008 at 01:38 PM.
jcorradino is offline  
Reply With Quote
Old 10-26-2008, 05:59 AM   #2 (permalink)
The Contributor
 
jcorradino's Avatar
 
Join Date: Sep 2008
Posts: 36
Thanks: 2
jcorradino is on a distinguished road
Default

so... no ideas?
__________________
Jason Corradino
Applications Developer, Interactive Support - Tribune Technology
J2EE Development, Script Tinkering - Develop, Support, and Maintain Tribune websites.
jcorradino is offline  
Reply With Quote
Old 10-30-2008, 01:37 PM   #3 (permalink)
The Contributor
 
jcorradino's Avatar
 
Join Date: Sep 2008
Posts: 36
Thanks: 2
jcorradino is on a distinguished road
Default

found it - Creating a Store Locator with PHP, MySQL & Google Maps - Google Maps API - Google Code
__________________
Jason Corradino
Applications Developer, Interactive Support - Tribune Technology
J2EE Development, Script Tinkering - Develop, Support, and Maintain Tribune websites.
jcorradino is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:46 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design