Did I find the right examples for you? yes no

# MAVProxy.modules.lib.mp_util.gps_distance

All Samples(30)  |  Call(30)  |  Derive(0)  |  Import(0)
```return distance between two points in meters,
coordinates are in degrees
thanks to http://www.movable-type.co.uk/scripts/latlong.html
```

```        def gps_distance(lat1, lon1, lat2, lon2):
'''return distance between two points in meters,
coordinates are in degrees
thanks to http://www.movable-type.co.uk/scripts/latlong.html'''
dLat = lat2 - lat1
dLon = lon2 - lon1

a = math.sin(0.5*dLat)**2 + math.sin(0.5*dLon)**2 * math.cos(lat1) * math.cos(lat2)
c = 2.0 * math.atan2(math.sqrt(a), math.sqrt(1.0-a))
```

```        while True:
start = mp_util.latlon_round((x,y), spacing)
dist = mp_util.gps_distance(x,y,x+w,y+h)
count = int(dist / spacing)
if count < 2:
```
```            return
(lat2,lon2) = self.coordinates(x, y)
distance = mp_util.gps_distance(lat2, lon2, lat, lon)
bearing  = mp_util.gps_bearing(lat2, lon2, lat, lon)
(state.lat, state.lon) = mp_util.gps_newpos(state.lat, state.lon, bearing, distance)
```
```                                                      mp_util.latlon_to_grid(self.click_pos))
if self.last_click_pos is not None:
distance = mp_util.gps_distance(self.last_click_pos[0], self.last_click_pos[1],
self.click_pos[0], self.click_pos[1])
bearing = mp_util.gps_bearing(self.last_click_pos[0], self.last_click_pos[1],
```

```        while True:
start = mp_util.latlon_round((x,y), spacing)
dist = mp_util.gps_distance(x,y,x+w,y+h)
count = int(dist / spacing)
if count < 2:
```
```            return
(lat2,lon2) = self.coordinates(x, y)
distance = mp_util.gps_distance(lat2, lon2, lat, lon)
bearing  = mp_util.gps_bearing(lat2, lon2, lat, lon)
(state.lat, state.lon) = mp_util.gps_newpos(state.lat, state.lon, bearing, distance)
```
```                                                      mp_util.latlon_to_grid(self.click_pos))
if self.last_click_pos is not None:
distance = mp_util.gps_distance(self.last_click_pos[0], self.last_click_pos[1],
self.click_pos[0], self.click_pos[1])
bearing = mp_util.gps_bearing(self.last_click_pos[0], self.last_click_pos[1],
```

```	def size(self):
'''return tile size as (width,height) in meters'''
(lat1, lon1) = self.coord((0,0))
(lat2, lon2) = self.coord((TILES_WIDTH,0))
width = mp_util.gps_distance(lat1, lon1, lat2, lon2)
(lat2, lon2) = self.coord((0,TILES_HEIGHT))
height = mp_util.gps_distance(lat1, lon1, lat2, lon2)
```
```	def distance(self, lat, lon):
'''distance of this tile from a given lat/lon'''
(tlat, tlon) = self.coord((TILES_WIDTH/2,TILES_HEIGHT/2))
return mp_util.gps_distance(lat, lon, tlat, tlon)

```
```			return (0,0)

dx = mp_util.gps_distance(lat, lon, lat, lon2)
if lon2 < lon:
dx = -dx
dy = mp_util.gps_distance(lat, lon, lat2, lon)
```

```	def size(self):
'''return tile size as (width,height) in meters'''
(lat1, lon1) = self.coord((0,0))
(lat2, lon2) = self.coord((TILES_WIDTH,0))
width = mp_util.gps_distance(lat1, lon1, lat2, lon2)
(lat2, lon2) = self.coord((0,TILES_HEIGHT))
height = mp_util.gps_distance(lat1, lon1, lat2, lon2)
```
```	def distance(self, lat, lon):
'''distance of this tile from a given lat/lon'''
(tlat, tlon) = self.coord((TILES_WIDTH/2,TILES_HEIGHT/2))
return mp_util.gps_distance(lat, lon, tlat, tlon)

```
```			return (0,0)

dx = mp_util.gps_distance(lat, lon, lat, lon2)
if lon2 < lon:
dx = -dx
dy = mp_util.gps_distance(lat, lon, lat2, lon)
```

```    (lat, lon) = (bounds[0]+bounds[2], bounds[1])
(lat, lon) = mp_util.gps_newpos(lat, lon, -45, 50)
ground_width = mp_util.gps_distance(lat, lon, lat-bounds[2], lon+bounds[3])
while (mp_util.gps_distance(lat, lon, bounds[0], bounds[1]) >= ground_width-20 or
mp_util.gps_distance(lat, lon, lat, bounds[1]+bounds[3]) >= ground_width-20):
```

```    (lat, lon) = (bounds[0]+bounds[2], bounds[1])
(lat, lon) = mp_util.gps_newpos(lat, lon, -45, 50)
ground_width = mp_util.gps_distance(lat, lon, lat-bounds[2], lon+bounds[3])
while (mp_util.gps_distance(lat, lon, bounds[0], bounds[1]) >= ground_width-20 or
mp_util.gps_distance(lat, lon, lat, bounds[1]+bounds[3]) >= ground_width-20):
```

```        for i in range(self.module('wp').wploader.count()):
distance = mp_util.gps_distance(lat, lon, w.x, w.y)
if best_distance == -1 or distance < best_distance:
best_distance = distance
```

```        for i in range(self.module('wp').wploader.count()):
distance = mp_util.gps_distance(lat, lon, w.x, w.y)
if best_distance == -1 or distance < best_distance:
best_distance = distance
```

```                                                        mavutil.mavlink.MAV_CMD_NAV_LAND,
distance += mp_util.gps_distance(lat, lon, w.x, w.y)
lat = w.x
lon = w.y
```

```                                                        mavutil.mavlink.MAV_CMD_NAV_LAND,