Longitude and Latitude Calculations

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
john_mcc1983
Forum Newbie
Posts: 1
Joined: Wed Oct 08, 2008 6:41 am

Longitude and Latitude Calculations

Post by john_mcc1983 »

I was wondering if anyone could help me with Longitude and Latitude calculations.

What I am trying to do is see if a longitude and latitude supplied by a user falls within a pre-defined circular area (unfortunately it has to be circular, it would have been easy working with a rectangular area)

The information I have is:

- The centre point (longitude and latitude) of the circular area and the radius of the area in miles. (stored in database)
- User supplied longitude and latitude co-ordinates (supplied via web site)

I am new to working with longitude and latitudes and not really sure where to start.

Any help would be greatly appreciated.

Thanks and regards

John
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

Re: Longitude and Latitude Calculations

Post by koen.h »

This should help.

Image

No seriously, looking at wikipedia it seems like it's not that simple. Maybe you could try using the google maps api.
visu
Forum Newbie
Posts: 4
Joined: Fri Jun 06, 2008 2:48 pm

Re: Longitude and Latitude Calculations

Post by visu »

Do some googling for 'haversine', 'haversine formula' and 'haversine distance', there's implementations for php/mysql/any other language you can think of.

Another alternative is the mysql spatial extension, never used it but seen it recommended by others, http://dev.mysql.com/doc/refman/5.0/en/ ... sions.html
Post Reply