Frappe Framework version 14 - Inverted latitude and longitude for Map View

When creating latitude and longitude fields, the map view show wrong pin position because Geolocation JSON wants the point defined has [longitude,latitude] instead of [latitude,longitude].

Original code.

def create_gps_markers(coords):
	"""Build Marker based on latitude and longitude."""
	geojson_dict = []
	for i in coords:
		node = {"type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": None}}
		node["properties"]["name"] = i.name
		node["geometry"]["coordinates"] = [i.latitude, i.longitude]
		geojson_dict.append(node.copy())

	return geojson_dict

Edited code (inverted latitude and longitude)

def create_gps_markers(coords):
	"""Build Marker based on latitude and longitude."""
	geojson_dict = []
	for i in coords:
		node = {"type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": None}}
		node["properties"]["name"] = i.name
		node["geometry"]["coordinates"] = [i.longitude, i.latitude]
		geojson_dict.append(node.copy())

	return geojson_dict
1 Like

We use leaflet which uses lat-long instead of long-lat (GeoJSON)

TIL :slight_smile:

Hi, I understand the usage of leaflet, I use the same library in other projects.
The problem is that the points where loaded with lat-lon coordinates inverted in the map view automatically generated by frappe framework when a doctype has latitude and longitude fields.

Please check the referenced code in my post that is related to version-14 production branch.

Regards,
Diego

1 Like

I can confirm this. the get_coords sql should already reverse lat and lng! V14.