## 3 replies

Last post Jul 17, 2008 11:48 PM by ramireddyindia

Participant

961 Points

492 Posts

### computing for distance in meter between two gps positions

hi,

i have two gps points,

1. 14.549259,121.024247
2. 14.549794,121.045299

i just need to compute for distance in meter between these two gps positions.

can somebody provide me a vb.net function.

thanks

All-Star

22512 Points

4552 Posts

### Re: computing for distance in meter between two gps positions

1. <div mce_keep="true"></div>
2. Dim lat1 As Double = 14.549259 <div></div>
3. Dim lon1 As Double = 121.024247
4. Dim lat2 As Double = 14.549794
5. Dim lon2 As Double = 121.045299
6. Dim R As Double = 6371000
7. Dim dLat As Double = (lat2 - lat1) * Math.PI / 180
8. Dim dLon As Double = (lon2 - lon1) * Math.PI / 180
9. Dim a As Double = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(lat1 * Math.PI / 180) * Math.Cos(lat2 * Math.PI / 180) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2)
10. Dim c As Double = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a))
11. Dim d As Double = R * c
12. ' d is the distance between those in meters.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.

Participant

961 Points

492 Posts

### Re: computing for distance in meter between two gps positions

hi ramireddyindia,

thanks for the reply. everything works fine now, i just have a little question.

#### ramireddyindia

Dim R As Double = 6371000

what is it for?

All-Star

22512 Points

4552 Posts