2019-09-24: completely edited as I made some progress …
I’m trying to display google maps with a coordinate path.
I get the following error:
[Error] InvalidValueError: at index 0: not a LatLng or LatLngLiteral with finite coordinates: not an Object
HTML code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example creates a 2-pixel-wide red polyline showing the path of
// the first trans-Pacific flight between Oakland, CA, and Brisbane,
// Australia which was made by Charles Kingsford Smith.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 22,
center: {lat: xx.xxx, lng: y.yyy,
mapTypeId: 'satellite'
});
var flightPlanCoordinatesData = new XMLHttpRequest();
flightPlanCoordinatesData.open( "GET", "https://1mylocalIP:port/rest/items/HusqvarnaMowerMapArrayDay/state" , false );
flightPlanCoordinatesData.send( null );
console.log(flightPlanCoordinatesData.responseText);
var flightPlanCoordinatesVariable = flightPlanCoordinatesData.responseText;
var flightPlanCoordinates = [
flightPlanCoordinatesVariable
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=mykey&callback=initMap">
</script>
</body>
</html>
Console output from “console.log(flightPlanCoordinatesData.responseText);” (values changed)
{lat: 99.999999, lng: 9.999999},{lat: 98.999999, lng: 8.999999},{lat: 97.999999, lng: 7.999999}
If I put the console output directly in the html script, the path is displayed correctly:
var flightPlanCoordinates = [
{lat: 99.999999, lng: 9.999999},{lat: 98.999999, lng: 8.999999},{lat: 97.999999, lng: 7.999999}
];
Unfortunately, I don’t have enough html knowledge to fix the latest piece of work, could someone help me ?