I'm tring to fill a javascript array with lat longs that I can use to put markers on a map from my model but it's riddled with errors and I'm not sure why.
<div id="map"></div>
<script>
var map,
points = [];
@foreach (var a in Model) {
//Error: The name 'points' does not exist in the current context
//Error: ) expected ; expected (at front and end brackets)
points.push({ lat: @a.Lat, lng: @a.Lon });
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: -34.397, lng: 150.644 },
zoom: 8
});
//Error: The name 'points' does not exist in the current context
@foreach (var p in points) {
var marker = new google.maps.Marker({ position: p });
//Error: The name 'marker' does not exist in the current context
//Error: The name 'map' does not exist in the current context
marker.setMap(map);
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=MyKey&callback=initMap"
async defer></script>
Model
public class Vehicle
{
[Key]
public int ID { get; set; }
public decimal Lon { get; set; }
public decimal Lat { get; set; }
public string VehType { get; set; }
public string Driver { get; set; }
}