Start and End Address on Map

I am writting an app that allows you to enter the start post code and end post code and then for it to automatically work out the distance between the 2. I am doing this on the IOS platform

Does anyone know how I can do this.

Thanks
Chris

Please do not post the same question twice.

Apologies for this, I just thought I had put it in the wrong place and so reposted it

You need the latitudes and longitudes of both places. Then calculate the great circle distance (Google it there are plenty of references, such as http://www.movable-type.co.uk/scripts/gis-faq-5.1.html).

If you want to find the real distance on real roads, that’s rather more complicated.

You need several things to achieve this. Location co-ordinates mapped to each and every location you might need to use; most databases out there typically start with latitude/longitude, or you could convert from that to a local co-ordinate system using a well known CRS (Coordinate Reference System). Since you mention using a postcode, I’ll assume you are talking about U.K, but other countries have similar, such as a zip code in the U.S.

Once you have every possible location with accurate coordinates, you then need to implement routing, which is the part that calculates the distance between the 2. You can easily calculate straight line distances with just a few lines of code, but this has limited use in the real world. For a more accurate distance you would use road routing, which would then return the driving distance between the 2 points. This is where you would implement a routing (Spatial) database, which contains coordinates for every known road location in your chosen area of coverage.

Using the necessary searching methods, you first retrieve coordinates for your start point (Or postcode), then do the same for your end point, then begin a search in your spatial database using the the sets of coordinates.

For any of this to be effective, you need good reliable data to begin with. Ordnance Survey has some fairly accurate datasets for this purpose. Some is free (OS Opendata), some is offered commercially and does not come cheap (OS ITN Network & AddressPoint).

As always there is an open source alternative to obtain similar data. For this, you should research OpenStreetMap (OSM); the data for this can be downloaded from several sources. I use download.geofabrik.de which covers many countries including UK, and has the covergae files broken down into the relevant regions.

Finally you need to consider which database to use for the mountain of data you typically need, and this databse must be spatially enabled. It can be done with the SQLite database using the Sptialite extension, or you could use PGSQL which also has its own spatial plugins. Other database systems also have spatial awareness e.g Oracle, but that is a paid for option.

Having setup your chosen database and all your data, there are usually a few conversions you will need to run to get the data in a format that is optimised for your application. Typically, a decent GIS / mapping application can assist with this.

Overall there is a lot of trial and error involved unless you are an expert in such matters; the whole process is not trivial.

The good thing is that once everything is setup and your data is complete and optimized, performing a routing enquiry is as simple as issuing an SQL query and working from the results.

HTH.

Stephen, Thank you so much for this. Seems very complicated just for something like this. I am still new to XOJO and have not played with it for a long time this kind of thing is just way over my head and dont even know where/how to start.

I thought it would be a lot simpler. But thank you anyway

Or just make calls to the GOOGLE or MAPQUEST API’s and let them do all the work for you.

MapKit also provides this functionality IF you are willing to dive into the declares for it.

I found out the above because I wanted offline routing. But as Dave points out, there is Google, Mapquest, Bing and a few other map providers if youre happy to retrieve the data online.

I have my Old application that i have make with LC. You have 2 Map pins (Origin- Destination) and calculate the distance for you!!
This is from Google API 3.
Bellow is the code if anyone want to use it.
if you Have any question feel free to ask…
The only change you need to do is to change the altitude from line 30,and longitude from line 31.

var origin1 = new google.maps.LatLng(38.078459, 23.734718); var destinationA = new google.maps.LatLng(38.078833, 23.736843);

[code]

html, body { height: 100%; margin: 0; padding: 0; } #map-canvas { height: 99%; width: 100%; } #content-pane { width: 100%; } #outputDiv { font-size:smaller; position: relative; bottom: -10px; }

[/code] When you send the above page the results that coming back is XML format. Just Get the [b]Nodes[/b] with [url=http://documentation.xojo.com/index.php/XMLDocument]xmlparse[/url] [code]origin_address destination_address element/duration/text element/distance/text[/code] And use it as you want If you want to see how this code working on the iOS then download my application from iTunes store. [url=https://itunes.apple.com/gr/app/find-my-store/id945374561?mt=8]Find My store[/url]