Currently, I am attempting to pass a Json String into my Javascript code in order to create a list of markers on a Google Map.
The map code functions properly as I have successfully tested it with a hard coded Json Object. However, now I need to fetch the data from my Model using the following code:
<script>
var markers = "@Model.JsonLifeboatLocations";
...
</script>
Despite not receiving any script errors, the above code does not display any markers.
Any suggestions on where I might be making a mistake?
View Model Getter:
public string JsonLifeboatLocations
{
get
{
return new JavaScriptSerializer().Serialize(LifeboatLocations);
}
}
Reference: The JavaScript code needed for displaying the markers
for (i = 0; i < markers.length; i++) {
var data = markers[i];
new google.maps.LatLng(data.Lat, data.Lon);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.Name
});
}