Mark location on geolocation map from latitude and longitude value

Hello, I want to mark the location on the geolocation map from latitude and longitude values. i have a doctype named live location with 4 fields -
1)user – link field with user field name is — user
2)latitude – data field – field name is — latitude
3)longitude – data field – field name is— longitude
4)location - geolocation field.

when I put the value of latitude and longitude it automatically mark on the map. (geolocation)
please help me to solve this.
– will be done server script or custom script for this ??? and what will it ?
any help will be appreciated.

Have you found any solutions?

In client Script you can use:

frm.fields_dict.location.map.setView([frm.doc.latitude, frm.doc.longitude], 13);

Name of Geolocation field (Map): location
Name of Latitude field: latitude
Name of Longitude field: longitude

The issue I observed however is that the map always returns to the default view after Saving

Cheers

frappe.ui.form.on(‘SE Checkin’, {
onload(frm) {
if(frm.doc.longitude && frm.doc.latitude){
frm.set_df_property(‘my_location’,‘options’,‘


.mapouter{position:relative;text-align:right;height:300px;width:100%;}.gmap_canvas {overflow:hidden;background:none!important;height:300px;width:100%;}
’);
frm.refresh_field(‘my_location’);
} else {
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(onPositionRecieved,locationNotRecieved,{ enableHighAccuracy: true});
}
}
},
validate(frm) {
frm.doc.google_link = “Google Maps” + frm.doc.latitude + “,” + frm.doc.longitude;
}
})

function onPositionRecieved(position){
var longitude= position.coords.longitude;
var latitude= position.coords.latitude;
console.log( position);
cur_frm.set_value(‘longitude’,longitude);
cur_frm.set_value(‘latitude’,latitude);
console.log(longitude);
console.log(latitude);
fetch(‘https://api.opencagedata.com/geocode/v1/json?q=‘+latitude+’+‘+longitude+’&key=ab43c3fb9f2f4e41b04146a741d23a06’)
.then(response => response.json())
.then(data => {
console.log(data);
var city=data[‘results’][0].components.state_district;
var state=data[‘results’][0].components.state;
var area=data[‘results’][0].components.works;
cur_frm.set_value(‘city’,city);
cur_frm.set_value(‘state’,state);
cur_frm.set_value(‘area’,area);
cur_frm.set_value(‘address’, data[‘results’][0].formatted);
console.log(data);
})
.catch(err => console.log(err));
cur_frm.set_df_property(‘my_location’,‘options’,‘


.mapouter{position:relative;text-align:right;height:300px;width:100%;}.gmap_canvas {overflow:hidden;background:none!important;height:300px;width:100%;}
’);
cur_frm.refresh_field(‘my_location’);
}

function locationNotRecieved(positionError){
console.log(positionError);
}

by this code you can get location from latitude and longitude value