Kuldeep Padhiar
Kuldeep Padhiar

Reputation: 19

Google Map v3 API: "InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number"

I have been getting the "InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a number" message and have reviewed previous posts but can't seem to find which line is causing the issue.

The below code seems to work but throws the above warning. I have tried parseFloat on lat and long values and on setPosition value but no joy.

  const flightPlanCoordinates1100_0 = [{
      lat: 51.52386762,
      lng: -0.059058666
    },
    {
      lat: 51.52394638,
      lng: -0.058520453
    },
    {
      lat: 51.52716833,
      lng: -0.05617915
    }, {
      lat: 51.54674506,
      lng: -0.059390801
    },
  ];

 

  // define the polyline attributes
  const flightPath1100_0 = new google.maps.Polyline({
    path: flightPlanCoordinates1100_0,
    geodesic: true,
    strokeColor: "Aqua",
    strokeOpacity: 1.0,
    strokeWeight: 2,
    draggable: true,
    map: map
  });

  // create an invisible marker for the label listener
  labelMarker = new google.maps.Marker({
    position: flightPath1100_0,
    map: map,
    visible: false
  });

  var myLabel = new Label();

  // lets add an event listener, if you move the mouse over the line, it will tell you the track id
  flightPath1100_0.addListener('mouseover', function(e) {
    labelMarker.setPosition(e.latLng)
    myLabel.bindTo('position', labelMarker, 'position');
    // Type the Track Id name here, this can be loaded using excel macro
    myLabel.set('text', "1100");
    myLabel.setMap(map);
  });

  flightPath1100_0.setMap(map);

  
  
  google.maps.event.addDomListener(window, 'load', initialize);

}

Upvotes: 0

Views: 455

Answers (1)

Kuldeep Padhiar
Kuldeep Padhiar

Reputation: 19

The issue as MrUpsidDown pointed out was that the position was not in latlng format, the below changes seemed to have worked

 labelMarker = new google.maps.Marker({
    position: new google.maps.LatLng(flightPath1100_0),
    map: map,
    visible: false
  });

Upvotes: 0

Related Questions