Geolocation field

Hello @revant_one, thanks for the work.

It works well in the desk side, but it seems that this geolocation field type cannot be seem in a web form. When I create a new field in the web form, I see the geoposition field from the doctype, but the is no “Geolocation” in the list of field type.

Is there any standard way to show this field in web form?

Cheers

1 Like

@revant_one I used your piece of code (link)

I’m running into a similar issue. I’m trying to read data from form field then change the market on the map. This is my code, but it doesn’t move the market.

frappe.ui.form.on("Shipment", "vessel_location", function(frm) {
    var imo = cur_frm.doc.imo_number_vessel;
    var latitude= 50.454100;
    var longitude= -2.370833;
    cur_frm.get_field("location").locate_control._marker._latlng.lat = latitude;
    cur_frm.get_field("location").locate_control._marker._latlng.lng = longitude;

});

Thank you much for the help

Use leafletjs docs/api
https://leafletjs.com/reference-1.6.0.html#marker-update

1 Like

hi @revant_one

Some leaflet plugins can be used via cdn by adding the relevant files in the html header. Is there any way to do this in an ERPNext doctype ?

Kindly advise

Thanks

Hi @revant_one

Any suggestions pls ? Also, if the html header approach isn’t feasible, could you pls give some guidance on how to add the plugin via custom script? If I can get a better idea how to add a plugin, I think I could figure the rest out

Thanks

I don’t know. I’ve not tried.

Hi @revant_one, I was actually referring to your statement above… I thought it inferred there was a known way of achieving this

Thanks anyway

That is how current plugins are added.

Oh, I see what you mean. Thanks a lot for the clarification

Cheers

Hi @chabito79

Could you pls give some more insight on how you achieved this? How were you able to access the map’s HTML? Did you have to use a separate field other than the geolocation field itself?

Thanks

I dont have the project’s code anymore…but I remember I ended up integrating google maps instead of leaflet.

I used an HTML field and injected the map on it (following the standard way)… here’s a nice tutorial about it.

Regards

1 Like

Thanks a lot @chabito79

This was very helpful indeed

Cheers!

This is the code for showing popup on the marker. The below code can be included on refresh(frm) trigger.

var map = frm.get_field("geolocation_field").map;
var latlng = L.latLng({'lat':<value>, 'lng': <value>});
var marker = L.marker(latlng);
			
map.flyTo(latlng, map.getZoom());
marker.addTo(map);
marker.bindPopup(<content>).openPopup();
5 Likes

that great

I want to use restapi to send geojson to erpnext. but I have a trouble, could you check this?
Thank you.

Check the json

Nested “features” is array of objects

1 Like

Thank for your reply, I tried fixed follow your suggestion but it still not work, the map is default, dont’ have a point here

dd = {
“name1”: “Hcm096”,
“odo”: 200,
“geolocation”: json.dumps(
{“type”: “FeatureCollection”,
“features”: [{
“type”: “Feature”,
“geometry”: {
“type”: “Point”,
“coordinates”: [
106.6964048,
10.7511488]
}
}
]
}
)
}
data = json.dumps(dd)
r = requests.post(url, data, auth=(‘59aa898bdfdf713’, ‘1365c7955faa000’))
print(r)

Example command:

curl -Ssl -X POST https://erp.example.com/api/resource/ToDo \
    -H "Content-Type: application/json" \
    -H "Authorization: token $api_key:$api_secret" \
    -H "Accept: application/json" \
    -d '{
        "description": "ToDo Mumbai",
        "todo_location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.867851,19.088689]}}]}"
    }'

todo_location is a custom Geolocation field added on ToDo

3 Likes

Hi all

Anyone got this error/warning on mobile app-android?

Geolocation error: application does not have sufficient geolocation permissions

If so, how did you resolve it?

Hi @glz

You’ll need to recompile the app yourself and include the Cordova Geolocation Plugin

Cheers