Im trying to calculate the center of the bounding box with these given points
(50.607041876988994, -1.3187316344406208, 52.40735812301099, 1.5737316344406207)
This is the code i done in python
def center_geolocation(geolocations):
"""
Provide a relatively accurate center lat, lon returned as a list pair, given
a list of list pairs.
ex: in: geolocations = ((lat1,lon1), (lat2,lon2),)
out: (center_lat, center_lon)
"""
x = 0
y = 0
z = 0
for lat, lon in geolocations:
lat = float(lat)
lon = float(lon)
x += cos(lat) * cos(lon)
y += cos(lat) * sin(lon)
z += sin(lat)
x = float(x / len(geolocations))
y = float(y / len(geolocations))
z = float(z / len(geolocations))
return (atan2(y, x), atan2(z, sqrt(x * x + y * y)))
However i keep on getting this error
line 64, in center_geolocation
for lat, lon in geolocations:
TypeError: 'float' object is not iterable
Can someone explain what im doing wrong or can someone correct the error i may have done,
thank you :)
from math import *
def center_geolocation(geolocations):
"""
Provide a relatively accurate center lat, lon returned as a list pair, given
a list of list pairs.
ex: in: geolocations = ((lat1,lon1), (lat2,lon2),)
out: (center_lat, center_lon)
"""
x = 0
y = 0
z = 0
for lat, lon in geolocations:
lat = float(lat)
lon = float(lon)
x += cos(lat) * cos(lon)
y += cos(lat) * sin(lon)
z += sin(lat)
x = float(x / len(geolocations))
y = float(y / len(geolocations))
z = float(z / len(geolocations))
return (atan2(y, x), atan2(z, sqrt(x * x + y * y)))
center_geolocation(
((50.607041876988994, -1.3187316344406208),
(52.40735812301099, 1.5737316344406207)))
There is not float error in the example you have given .... I do not like the output - but that was not the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With