Try ERPNext Buy Support Partners Foundation Foundation Members

Geolocation field

How field works?

{  
   "type":"FeatureCollection",
   "features":[  
      {  
         "type":"Feature",
         "properties":{  
            "point_type":"circle",
            "radius":1976.1269632232793
         },
         "geometry":{  
            "type":"Point",
            "coordinates":[  
               72.854548,
               19.096511
            ]
         }
      },
      {  
         "type":"Feature",
         "properties":{  
            "point_type":"circle",
            "radius":1592.425070031574
         },
         "geometry":{  
            "type":"Point",
            "coordinates":[  
               72.846737,
               19.117922
            ]
         }
      }
   ]
}
  • same example screenshot
    Screenshot from 2017-10-23 16-17-58
  • important custom properties
"properties":{  
    "point_type":"circle",
    "radius":1976.1269632232793
}
  • If the field is empty and the origin is secure or localhost it will auto-locate the map to current location.
  • If the field is empty and the origin is not secure the map will show Frappe office :smiley: @vishal
  • If the field has values, It will try to fit the drawings in map bounds.
  • There is a refresh button and locate button on map
  • Allowed drawings : connecting lines, polygon, rectangles, circles, marker and circle marker.
  • Edit and delete buttons are part of draw toolbar.
  • Field is not shown in print format
  • Depends on other free / open source projects leafletjs.com, leaflet plugins and https://www.openstreetmap.org/about

For custom app developers :

  • Data stored in the field is accessible by field name, e.g self.map_field or frm.doc.map_field as a geojson featurecollection string.
  • You can load it as a layer on google maps https://developers.google.com/maps/documentation/javascript/reference#Data or any map which allows geojson featurecollection
  • important custom properties mentioned above are required to load the data in frappe’s field, you can add additional properties like arrival_time, departure_time, mode_of_transport etc as a key-value pair under properties. e.g. Use in mobile apps for tracking resources
13 Likes

Good feature. I was thinking to open a feature request for this.

I vote on Geolocations.

It would be great if we can add costumer locations into their records. (And would be great if we can get the coordinates through official mobile app)

Geolocation is fine.
Maybe the easiest to translate for everyone would be “Location” as this is the default term used in English Language Android/iOS etc.
Either that or “Locale” or “Map”. Just as all of these words are shorter than geolocation. The icon should be standard location “pin” icon.

I planned a similar feature and planned to use “geocode”. It’s shorter than “geolocation” and more meaningful than"geozone" but not worth getting upset over. “GeoJSON” is what is literally is, so that’d be fine too.

“Geolocation” itself will be more meaningful.

Hi @revant_one ,
I have successfully added a geolocation field (thanks to your contribution to this post!) to show all features (markers) from a featurecollection on a map , but i want to show the marker name (passed in properties as name on the featurecollection) when I click on the marker.

I have no idea on how to do that.

I tried:

  • Creating an attribute on the map’s HTML for each marker (and the calling it with jquery to show a tooltip.
  • Using the bindPopup method on a marker (but couldn’t find a way to call it).

I have not been able to make it work…Do you have any pointers?

I’d really appreciate your time and effort.

The field is part of framework

It is here : https://github.com/frappe/frappe/blob/develop/frappe/public/js/frappe/form/controls/geolocation.js

Also check leaflet API documentation for what you need.
https://leafletjs.com/plugins.html

Thanks a lot!

is the geolocation data accessible via API? and if so how can i extract it?

Here are relevant docs

geolocation https://erpnext.org/docs/user/manual/en/customize-erpnext/articles/field-types.html

https://frappe.io/docs/user/en/guides/integration/rest_api

A forum search should yield lots of ideas and pointers

Yes that i am aware but when you enable the location field in customer and do the get request of the same customer after creating the customer. Location is not part of the json response.

I have also tried using FrappeClient in bench console and still no location data being returned back in the response

How can i get the location of the customer?

Thanks i have seen what you meant. it works now

Excellent good to hear - of course whatever ‘ah-ha’ learning tip notes that you can add for your own recall reference will help others follow in your steps too!

I have been going through the thread above but it doesn’t really my question so I was wondering if there way of adding description/details for points, polygons in the geolocation field on. For, example if I have more than one point and I want to give the first point a description as “point1” and the second as “point2” when the user hovers over the point as shown in the screenshot below.

You cannot name the points via UI.

The data is just geojson feature collection, you can save additional data manually (some customisation), if storing data is important. It won’t reflect on UI.

If you wish to add the feature, add appropriate leaflet plugin. Note that there is limited space on geolocation field, only important plugins are kept on UI.

@revant_one thanks alot for the prompt reply, I will have to think of another way to solve the issue. You also said the geojson field has limited space is there any other way of storing an unlimited number of points on a map for example if i want to see all the assets of a company in on one map in erpnext or can the max length of geojson field be customized.

For storing data there is no restriction, it is just another field in database.

The UI has lot of functionality already, it can draw polygons, circles, place points. It becomes cluttered when field is placed in 2 column layout.

For any developer who wish to add this to features, there is a plugin available.

@revant_one thanks so much for the help I will look into it