【发布时间】:2016-04-05 14:57:00
【问题描述】:
我试图用这些给定点计算边界框的中心
(50.607041876988994, -1.3187316344406208, 52.40735812301099, 1.5737316344406207)
这是我在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)))
但我不断收到此错误
line 64, in center_geolocation
for lat, lon in geolocations:
TypeError: 'float' object is not iterable
谁能解释我做错了什么,或者谁能纠正我可能做的错误,
谢谢你:)
【问题讨论】:
-
你将什么作为参数传递给函数?
-
我试图传递我计算的边界框的这些坐标(50.607041876988994,-1.3187316344406208,52.40735812301099,1.5737316344406207)
标签: python api geolocation latitude-longitude bounding-box