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: