Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Decimal('37.351158') is not JSON serializable #12

Closed
itsahsiao opened this issue May 13, 2016 · 2 comments
Closed

TypeError: Decimal('37.351158') is not JSON serializable #12

itsahsiao opened this issue May 13, 2016 · 2 comments
Labels

Comments

@itsahsiao
Copy link
Owner

itsahsiao commented May 13, 2016

While working on Issue #6 , got this error at the route for JSON file of user's restaurant visits

Need to see how to pass the latitude and longitude that are Decimal types, which is not accepted by JSON

@itsahsiao
Copy link
Owner Author

itsahsiao commented May 13, 2016

Could convert latitude and longitude to strings/floats, which works:

"latitude": float(visit.restaurant.latitude),
"longitude": float(visit.restaurant.longitude)

But read that converting to floats could have rounding issues. Did not see any issues when I converted these two to floats, but saw solutions suggesting simplejson, which has support for Decimal type
http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object

Used simplejson as json

@itsahsiao
Copy link
Owner Author

When creating javascript function (for loop) to access each of user's visited restaurants and plotting markers, got this error in the browser console:

InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number

Per solution (http://stackoverflow.com/questions/20585055/uncaught-invalidvalueerror-setposition-not-a-latlng-or-latlngliteral-in-prope), numbers are not being passed in for latitude and longitude.

Decided to not use simplejson and just convert the latitude and longitude to floats in server.py, which fixed the error and markers now being plotted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant