ERPNext Conference 2019* ERPNext.com Blog

Get coordinates in doctypes - server side custom script

custom_script

#1

Hello I want to share this custom script to get the latitude and longitude of a doctype:

from __future__ import unicode_literals

import frappe
import json
from six import string_types


@frappe.whitelist()
def get_coords(doctype, names):
'''get list of coordinates in form
returns {name: ['latitude', 'longitude']}'''

if isinstance(names, string_types):
	names = json.loads(names)

coords = frappe.db.get_list(doctype, filters={
	'name': ('in', names)
}, fields=['latitude', 'longitude','name as docname'])

out = frappe._dict()
for i in coords:
	out[i.docname] = out.get(i.docname, [])
	out[i.docname].append(i.latitude)
	out[i.docname].append(i.longitude)

return out

Example:


#2

Thanks for your contribution @Ernesto

No wiki pages refer to geolocation related examples Links to Wiki pages - please add to the list thanks

So adding this link to your page will help others to find your script Geolocation field