Get coordinates in doctypes - server side custom script

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

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, [])

return out


1 Like

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

1 Like

hi, what do referring to by the names argument?
thx for help