gopal krishna mareti
gopal krishna mareti

Reputation: 367

i am trying to create a geofence from the web browser and created a dynamic marker which gives an alert when crossed

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);
   });
}

Upvotes: 3

Views: 176

Answers (2)

Chinmay Jain
Chinmay Jain

Reputation: 11

I faced the same issue, it seems like HERE maps used to have a function marker.getPosition() in their earlier version but has changed it in the latest one to marker.getGeometry().

You can try to see the response using console.log(marker.getGeometry()).

Upvotes: 1

Michel
Michel

Reputation: 28339

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.

Upvotes: 1

Related Questions