Question

This is an example from my jsonData:

"lineformap":"new google.maps.LatLng(52.25602231800669, 6.160540580749512),new google.maps.LatLng(52.25543780780041, 6.1602723598480225),new google.maps.LatLng(52.255818725438296, 6.160014867782593)"

and this is my code: (no line appears) When i copy the data in to the code the lines are visable on the map Who can help me with this

var poly;
var map;
function initialize() {
    var latlng = new google.maps.LatLng(52.2554, 6.1627);
  var myOptions = {
    zoom: 15,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};

    var bermudaTriangle;

    map = new google.maps.Map(document.getElementById("ObjectMap"), myOptions);
    $.getJSON('/api/dbklineforbws', function (createbws) {
        $(createbws).each(function (i, itemb) {
            // Define the LatLng coordinates for the polygon's path.
            var flightPlanCoordinates = [
            itemb.lineformap
          ];

            var flightPath = new google.maps.Polyline({
                path: flightPlanCoordinates,
                geodesic: true,
                strokeColor: '#FF0000',
                strokeOpacity: 1.0,
                strokeWeight: 2
            });



            flightPath.setMap(map);
        });
    });
    }


    google.maps.event.addDomListener(window, 'load', initialize);
Was it helpful?

Solution

For me it's very strange usage of json file. But, to make it work I'd change json file to:

{
"lineformap": "[new google.maps.LatLng(52.25602231800669, 6.160540580749512),new google.maps.LatLng(52.25543780780041, 6.1602723598480225),new google.maps.LatLng(52.255818725438296, 6.160014867782593)]"
}

and

var flightPlanCoordinates = [
    itemb.lineformap
];

to

var flightPlanCoordinates = eval(itemb.lineformap);

to get polyline.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top