const getAgenApi = () => {
this.longitudeNow = parseFloat(106.105104103);
this.latitudeNow = parseFloat(-123.123);
// other code...
};
mymap.on("geosearch/showlocation", function (result) {
console.log(result);
// Remove marker
marke.forEach(function (maker) {
mymap.removeLayer(maker);
});
this.longitudeNow = result.location.x;
this.latitudeNow = result.location.y;
// Draw updated locations!
GetAgenApi();
});
Can anyone fix this code to update the latitude and longitude?
CodePudding user response:
As Pi and Mash wrote in comment, your variables are out of scope.
You have to convert mymap.on
callback to use arrow function:
mymap.on("geosearch/showlocation", (result) => {
// Now this.longitudeNow points valid variable
this.longitudeNow = result.location.x;
// ...
});