-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
What happened?
I use an OpenCageGeocoderService. I have 2 similar search queries, which result in these 2 responses from the OpenCageData, see "Response A" and "Response B" below.
Those responses target a very similar area, around 45°30'N" 74°32'W". However, Cesium.OpenCageGeocoderService treats the Reponse A to send me to the Antarctic, while Reponse B is treated to send me to Canada. Apparently, their resulting latitude and longitude are switched!
But the only major difference between those responses is that Response B also has the bounds property, which Response A has not. This lead me to this line in Cesium code:
cesium/packages/engine/Source/Core/OpenCageGeocoderService.js
Lines 114 to 125 in 8e4375e
| if (defined(bounds)) { | |
| destination = Rectangle.fromDegrees( | |
| bounds.southwest.lng, | |
| bounds.southwest.lat, | |
| bounds.northeast.lng, | |
| bounds.northeast.lat, | |
| ); | |
| } else { | |
| const lon = resultObject.geometry.lat; | |
| const lat = resultObject.geometry.lng; | |
| destination = Cartesian3.fromDegrees(lon, lat); | |
| } |
There, without the bounds field, lat and lon are switched.
This seems like a bug to me, but I also know that some geocodes sometimes switch the latitude and the longitude - in this case, it is obviously wrong, but maybe the Cesium developers had something in mind with that? I cannot imagine that this behaviour hasn't caught anyone's attention, getting seemingly wrong geocoding results.
Response A "barb" --> "Barb, Ontario, Canada"
Query: https://api.opencagedata.com/geocode/v1/json?q=barb&key=<myOpenCageKey>
{
"documentation": "https://opencagedata.com/api",
"licenses": [
{
"name": "see attribution guide",
"url": "https://opencagedata.com/credits"
}
],
"results": [
{
"annotations": {
"DMS": {
"lat": "45° 31' 0.98400'' N",
"lng": "74° 32' 21.01200'' W"
},
"MGRS": "18TWR3599240481",
"Maidenhead": "FN25rm54hb",
"Mercator": {
"x": -8297662.449,
"y": 5672775.92
},
"OSM": {
"note_url": "https://www.openstreetmap.org/note/new#map=17/45.51694/-74.53917&layers=N",
"url": "https://www.openstreetmap.org/?mlat=45.51694&mlon=-74.53917#map=17/45.51694/-74.53917"
},
"UN_M49": {
"regions": {
"AMERICAS": "019",
"CA": "124",
"NORTHERN_AMERICA": "021",
"WORLD": "001"
},
"statistical_groupings": [
"MEDC"
]
},
"callingcode": 1,
"currency": {
"alternate_symbols": [
"C$",
"CAD$"
],
"decimal_mark": ".",
"disambiguate_symbol": "C$",
"html_entity": "$",
"iso_code": "CAD",
"iso_numeric": "124",
"name": "Canadian Dollar",
"smallest_denomination": 5,
"subunit": "Cent",
"subunit_to_unit": 100,
"symbol": "$",
"symbol_first": 1,
"thousands_separator": ","
},
"flag": "🇨🇦",
"geohash": "f24fzy45rkw7jqy5182q",
"qibla": 58,
"roadinfo": {
"drive_on": "right",
"speed_in": "km/h"
},
"sun": {
"rise": {
"apparent": 1768394160,
"astronomical": 1768387800,
"civil": 1768392180,
"nautical": 1768389960
},
"set": {
"apparent": 1768426740,
"astronomical": 1768433100,
"civil": 1768428780,
"nautical": 1768430940
}
},
"timezone": {
"name": "America/Toronto",
"now_in_dst": 0,
"offset_sec": -18000,
"offset_string": "-0500",
"short_name": "EST"
},
"what3words": {
"words": "billionaire.inaccuracy.surgery"
}
},
"components": {
"ISO_3166-1_alpha-2": "CA",
"ISO_3166-1_alpha-3": "CAN",
"ISO_3166-2": [
"CA-ON"
],
"_category": "place",
"_normalized_city": "Barb",
"_type": "city",
"continent": "North America",
"country": "Kanada",
"country_code": "ca",
"state": "Ontario",
"state_code": "ON",
"town": "Barb"
},
"confidence": 9,
"formatted": "Barb, Ontario, Kanada",
"geometry": {
"lat": 45.51694,
"lng": -74.53917
}
}
],
"status": {
"code": 200,
"message": "OK"
},
"stay_informed": {
"blog": "https://blog.opencagedata.com",
"mastodon": "https://en.osm.town/@opencage"
},
"thanks": "For using an OpenCage API",
"timestamp": {
"created_http": "Wed, 14 Jan 2026 15:20:31 GMT",
"created_unix": 1768404031
},
"total_results": 1
}Reponse B "barb, ontario" --> "East Hawkesbury, Ontario, Canada"
Query: https://api.opencagedata.com/geocode/v1/json?q=barb%2C%20ontario&key=<myOpenCageKey>
{
"documentation": "https://opencagedata.com/api",
"licenses": [
{
"name": "see attribution guide",
"url": "https://opencagedata.com/credits"
}
],
"results": [
{
"annotations": {
"DMS": {
"lat": "45° 30' 56.49192'' N",
"lng": "74° 32' 2.80464'' W"
},
"MGRS": "18TWR3638840345",
"Maidenhead": "FN25rm53vs",
"Mercator": {
"x": -8297099.439,
"y": 5672578.339
},
"OSM": {
"edit_url": "https://www.openstreetmap.org/edit?node=2028150901#map=17/45.51569/-74.53411",
"note_url": "https://www.openstreetmap.org/note/new#map=17/45.51569/-74.53411&layers=N",
"url": "https://www.openstreetmap.org/?mlat=45.51569&mlon=-74.53411#map=17/45.51569/-74.53411"
},
"UN_M49": {
"regions": {
"AMERICAS": "019",
"CA": "124",
"NORTHERN_AMERICA": "021",
"WORLD": "001"
},
"statistical_groupings": [
"MEDC"
]
},
"callingcode": 1,
"currency": {
"alternate_symbols": [
"C$",
"CAD$"
],
"decimal_mark": ".",
"disambiguate_symbol": "C$",
"html_entity": "$",
"iso_code": "CAD",
"iso_numeric": "124",
"name": "Canadian Dollar",
"smallest_denomination": 5,
"subunit": "Cent",
"subunit_to_unit": 100,
"symbol": "$",
"symbol_first": 1,
"thousands_separator": ","
},
"flag": "🇨🇦",
"geohash": "f24fzvvuj7cxu3x0p43h",
"qibla": 58,
"roadinfo": {
"drive_on": "right",
"speed_in": "km/h"
},
"sun": {
"rise": {
"apparent": 1768394160,
"astronomical": 1768387800,
"civil": 1768392120,
"nautical": 1768389960
},
"set": {
"apparent": 1768426740,
"astronomical": 1768433100,
"civil": 1768428780,
"nautical": 1768430940
}
},
"timezone": {
"name": "America/Toronto",
"now_in_dst": 0,
"offset_sec": -18000,
"offset_string": "-0500",
"short_name": "EST"
},
"what3words": {
"words": "frock.reduced.excellency"
}
},
"bounds": {
"northeast": {
"lat": 45.5256922,
"lng": -74.5241124
},
"southwest": {
"lat": 45.5056922,
"lng": -74.5441124
}
},
"components": {
"ISO_3166-1_alpha-2": "CA",
"ISO_3166-1_alpha-3": "CAN",
"ISO_3166-2": [
"CA-ON"
],
"_category": "place",
"_normalized_city": "East Hawkesbury",
"_type": "hamlet",
"city": "East Hawkesbury",
"continent": "North America",
"country": "Kanada",
"country_code": "ca",
"county": "Prescott and Russell Counties",
"locality": "Barb",
"state": "Ontario",
"state_code": "ON",
"state_district": "Eastern Ontario"
},
"confidence": 8,
"formatted": "East Hawkesbury, Ontario, Kanada",
"geometry": {
"lat": 45.5156922,
"lng": -74.5341124
}
}
],
"status": {
"code": 200,
"message": "OK"
},
"stay_informed": {
"blog": "https://blog.opencagedata.com",
"mastodon": "https://en.osm.town/@opencage"
},
"thanks": "For using an OpenCage API",
"timestamp": {
"created_http": "Wed, 14 Jan 2026 15:21:24 GMT",
"created_unix": 1768404084
},
"total_results": 1
}Reproduction steps
- Use OpenCageGeocoderService and mock its results.
- Check the resulting coordinates that Cesium makes of the geocoder results.
Sandcastle example
No response
Environment
Browser: Firefox, Chrome
CesiumJS Version: 1.136, but the linked Cesium code is the current one.
Operating System: Windows