The following codes are in two different files and i am taking the values from the UI itself i am keeping the layer id constant like "1234".
But i am getting this following error -TypeError: marker1.getPosition is not a function
marker code--
var marker1 =new H.map.Marker(center, {volatility: true});
var geofencing=platform.getGeofencingService();
map.addObject(marker1);
map.addEventListener("tap",ev=>{
var target =ev.target;
map.removeObject(marker1);
marker1 = new H.map.Marker(map.screenToGeo(ev.currentPointer.viewportX,ev.currentPointer.viewportY));
map.addObject(marker1);
geofencing.request(
H.service.extension.geofencing.Service.EntryPoint.SEARCH_PROXIMITY,
{
"layer_ids":["1234"],
"proximity":marker1.getPosition().lat + "," + marker1.getPosition().lng,
"key_attributes":["NAME"]
},
result=>{
alert("within the geofence");
},
error =>{
console.error(error);
}
);
});
geofence code--
import {hereCredentials } from './Configurations.js';
import {platform,map} from './main.js';
document.getElementById("geofencesub").onclick=function geofence(){
var latitude=document.getElementById("lat").value;
var longitude=document.getElementById("lng").value;
var radius=document.getElementById("rad").value;
var lname =document.getElementById("lname").value
var circle = new H.map.Circle({lat: latitude, lng: longitude},radius);
map.addObject(circle);
var geo1 = circle.getGeometry();
var wkt = geo1.toString();
var zip = new JSZip();
zip.file("data.wkt","NAME\tWKT\n"+"testfence"+"\t"+wkt);
zip.generateAsync({type:"blob"}).then(content =>{
var formData= new FormData();
formData.append("zipfile",content);
axios.post("https://gfe.api.here.com/2/layers/upload.json",formData,{
headers:{
"content-type" : "multipart/form-data"
},
params:{
"app_id":hereCredentials.id,
"app_code":hereCredentials.code,
"layer_id":lname
}
}).then(result => {
console.log(result);
},error => {
console.error(error);
});
},error => {
console.error(error);
});
}
You get the error "marker1.getPosition is not a function" because getPosition is indeed not a function of H.map.Marker.
Try marker1.getGeometry() instead.
The function getGeomery is the function to use, in order to get the marker location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With