Monday, May 20, 2024
37
rated 0 times [  40] [ 3]  / answers: 1 / hits: 7106  / 10 Years ago, tue, july 8, 2014, 12:00:00

I was trying to draw a dynamic polyline in Javascript using Google Map API v3, Here is the Code snippet which i am using :



var map=new google.maps.Map(document.getElementById(googleMap),mapProp);
var myTrip=new Array();
//var y=new google.maps.LatLng(28.360012,77.031527);
//var z=new google.maps.LatLng(28.360124,77.031429);
myTrip.push(new google.maps.LatLng(28.360012,77.031527));
myTrip.push(new google.maps.LatLng(28.360124,77.031429));
myTrip.push(new google.maps.LatLng(28.361024,77.034129));
var flightPath=new google.maps.Polyline({
path:myTrip,
strokeColor:#0000FF,
strokeOpacity:0.8,
strokeWeight:2
});
flightPath.setMap(map);
google.maps.event.addDomListener(window, 'load', initialize);


This isn't drawing Polyline on the map.



Can someone please help me with this ?


More From » google-maps-api-3

 Answers
3

You're missing an initialize function:



function initialize() {
var mapProp = {
center: new google.maps.LatLng(28.360012, 77.031527),
zoom: 18,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map=new google.maps.Map(document.getElementById(googleMap),mapProp);
var myTrip=new Array();
myTrip.push(new google.maps.LatLng(28.360012,77.031527));
myTrip.push(new google.maps.LatLng(28.360124,77.031429));
myTrip.push(new google.maps.LatLng(28.361024,77.034129));
var flightPath=new google.maps.Polyline({
path:myTrip,
strokeColor:#0000FF,
strokeOpacity:0.8,
strokeWeight:2
});
flightPath.setMap(map);
}

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

[#44063] Sunday, July 6, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austonjuancarlosb

Total Points: 238
Total Questions: 89
Total Answers: 99

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;