Python Forum

Full Version: [SOLVED] [geopy] "ValueError: too many values to unpack (expected 2)"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I need to draw a circle around a location set by its latitude + longitude.

For some reason, geopy isn't happy with the following:

import geopy
import geopy.distance
import gpxpy
import gpxpy.gpx

center = geopy.Point(51.519, -0.1263)

d = geopy.distance.distance(kilometers=5)

for index in range(0, 359):
	final = d.destination(point=center, bearing=index).format_decimal()
	#Does display two items successfully, separated by comma
	print(final)

	#ValueError: too many values to unpack (expected 2)
	#latitude,longitude = d.destination(point=center, bearing=index).format_decimal()

	#AttributeError: 'str' object has no attribute 'latitude'
	#latitude,longitude = final.latitude,final.longitude
Any idea why?

Thank you.
Point.format_decimal() method return string (see source code). So, when you try to unpack it it try to bind every char to a name.
Thank you!

latitude,longitude = d.destination(point=center, bearing=index).format_decimal().split(',')