i want draw shapes given coordinates on google maps. when try in way: http://jsfiddle.net/zzhy/4auzbjd5/3/ drawing not showing in correct place. how can fix it?
var coordinates = r[0].split(":"); var flightplancoordinates = new array(); var bounds = new google.maps.latlngbounds(); for(i=0;i<coordinates.length;i++) { var point =new google.maps.latlng(coordinates[i].split(',')[0],coordinates[i].split(',')[1]); bounds.extend(point); flightplancoordinates.push(point); } var flightpath = new google.maps.polyline({ path: flightplancoordinates, geodesic: true, strokecolor: '#ff0000', strokeopacity: 1.0, strokeweight: 2 }); flightpath.setmap(map); map.fitbounds(bounds); console.log("flightplancoordinates:" + flightplancoordinates); console.log("bounds:" + bounds);
as seems order of array-items longitude,latitude
, google.maps.latlng
expects latitude,longitude
.
switch order of arguments:
var point =new google.maps.latlng(coordinates[i].split(',')[1],coordinates[i].split(',')[0]);