Domanda

Firstly I apologize for the Title! I couldn't think how to word it!

I have a database with all the area codes in the UK with their average latitudes and longitudes. Now I want to be able to calculate which area codes are within 'n' miles from another.

I tried running a massive calculation on my local host to work out all the distances and store them in a massive database, so all i have to do is look up the distances later, but it ran out of memory, and I'm wondering if that's the best way to go about it? Am I overlooking an easy way to calculate it on the fly?

So to make it clear, I want people to be able to enter an area code and a range in miles, and then get all the area codes within that range. The information i have available is a database with the fields:

| Postcode_ID | Pcode | GRID_N | GRID_E | Latitude | Longitude |

È stato utile?

Soluzione

There are several methods to achieve what you want.

  1. Check out the "Haversine Formula" for distance calculation

  2. Have a look at Google Maps API examples on google as these may provide insight on how to solve the problem

  3. To store the I recommend using a PostgreSQL Database togehter with PostGIS

About PostGIS (quote from the site):

PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL.

If you'll be able to use the above setup, working with the db data will be way easier.

 
This might also be useful:

PHP Postal (Zip) Code Range and Distance Calculation

Have your eyes roll over this and let me know what you think.

Good luck.

Altri suggerimenti

A similar question has been answered here How to calculate distance from lat/long in php?

You need to calculate the radius given the distance and determine which additional zip codes are inside of the circle.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top