I have a bit of a strange problem attempting to rotate an icon to indicate a vehicle's location. My json contains the bearing of the vehicle and if the vehicle is moving then the bearing is passed into the movingVehicle object which is then used when the marker is created. The issue I have is that every marker is at 200 degrees. I have stepped through the code and see that the correct bearing is passed through as part of the icon properties, but after the script finishes and all the markers are drawn, they are all at 200 degrees.
Something obvious?
var map;
var markersArray = [];
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(52.68, -1.26),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var movingVehicle = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
fillColor: "green",
fillOpacity: 1,
scale: 3,
strokeColor: "green",
strokeWeight: 1,
rotation:0
};
var staticVehicle = {
path: google.maps.SymbolPath.CIRCLE,
fillColor: "red",
fillOpacity: 1,
scale: 3,
strokeColor: "red",
strokeWeight: 5
};
function vehicleState(speed,bearing){
if (speed){
movingVehicle.rotation = bearing;
return movingVehicle;
}
else
{
return staticVehicle;
}
};
$(function(){
map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);
$.getJSON( PATH_TO_MY_JSON_WOULD_BE_HERE, function(data) {
$.each( data.vehicles, function(i, vehicle) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(vehicle.lat, vehicle.long),
title:vehicle.vehicle,
draggable: false,
map: map,
icon: vehicleState(vehicle.speed,vehicle.bearing)
});
markersArray.push(marker);
});
});
});
sample json
{"vehicle":"xxxxLCJ","time":"2013-01-25T18:33:19","lat":53.47766,"long":-2.335671,"speed":24.5562,"bearing":231},
{"vehicle":"xxxxLCN","time":"2013-01-25T15:07:36","lat":52.45257,"long":1.604016,"speed":36.4176,"bearing":138},
{"vehicle":"xxxxLCP","time":"2013-01-25T23:17:12","lat":53.24011,"long":-0.554743,"speed":0,"bearing":0},