I am working right now with MongoDB and Java in Eclipse. I want to represent coordinates in the API of Google Maps from a JSON document.
I have in the JSON document two attributes,latitude and longitude, both of them are double. But when i do this:
List<Pair<Double, Double>> coordenadas = new ArrayList<Pair<Double, Double>>();
Pair<Double, Double> coordenadasAirport;
MongoCursor<Document> cursor = collection.find().iterator();
try {
while (cursor.hasNext()) {
Double latitude = cursor.next().getDouble("latitude").doubleValue();
Double longitude = cursor.next().getDouble("longitude").doubleValue();
The second one, longitude, give me this error:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
How to solve this?
RESOLVED:
Thanks for try to help me. Finally i solved this problem. The problem was the import because when i do the import of the JSON to the database of MongoDB this database assigns the type of data that the DB wants so some data of latitude and longitude have the type Int32 and other data have the type Double.
Regards.
cursor.next().getDouble("latitude").doubleValue();return doule or int ? i guess it returns double