You are not logged in.
- Topics: Active | Unanswered
Announcement
Please create new topics on the new site at community.openstreetmap.org. We expect the migration of data will take a few weeks, you can follow its progress here.***
Pages: 1
#1 2010-10-28 18:27:09
- Avtar
- Member
- Registered: 2010-10-28
- Posts: 2
Geocoding for openstreetmap
Hi Team,
I have 2 text box one is called from address and another one is called to address. Now I have search button on click of search button i want to display the distance between from address and to address.
Example:
Suppose I have London in from address and France in to address now if i click on search button it should show the distance between these two places.
How I can do that, I know I have to do geocoding for that but I am a very novice person in geocoding.
Could you please let me know the steps or sample code for this.
Thanks in advance
Avtar
Offline
#2 2010-10-29 10:29:50
- Lambertus
- Inactive

- From: Apeldoorn (NL)
- Registered: 2007-03-17
- Posts: 3,269
- Website
Re: Geocoding for openstreetmap
You can use the Nominatim service to do address to location lookups.
Do you need the straight distance or do you need the distance using roads and different types of transport? The first can be solved by a simple calculation using e.g. the Great Circle Distance Formula (see below) and the second needs a routing application (i.e. shortest path).
function getDistanceKm($latitudeFrom, $longitudeFrom, $latituteTo, $longitudeTo) {
// 1 degree equals 0.017453292519943 radius
$degreeRadius = deg2rad(1);
// convert longitude and latitude values to radians before calculation
$latitudeFrom *= $degreeRadius;
$longitudeFrom *= $degreeRadius;
$latituteTo *= $degreeRadius;
$longitudeTo *= $degreeRadius;
// apply the Great Circle Distance Formula
$d = sin($latitudeFrom) * sin($latituteTo) + cos($latitudeFrom)
* cos($latituteTo) * cos($longitudeFrom - $longitudeTo);
return (6371.0 * acos($d));
}Mapping tools: Garmin GPSmap 60CSx, Giant Terrago 2002
Offline
Pages: 1