谷歌地图v3 API:"InvalidValueError: setPosition: not a LatLng or LatLngLiteral: in property lat: not a nu



我一直在获得"InvalidValueError: setPosition: not a LatLng或LatLngLiteral: in property "消息,并审查了以前的帖子,但似乎找不到哪一行引起的问题。

下面的代码似乎可以工作,但会抛出上面的警告。我已经尝试过parseFloat对后期和长值和setPosition值,但没有乐趣。

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

MrUpsidDown指出的问题是,该位置不是latlng格式,下面的更改似乎已经起作用了

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

最新更新