Can anyone help me with this problem, i'm getting data from the server and doing a foreach loop to get all the co-ordinates for the markers in a google map using gmap3.
Problem is it only displays 1 marker on the map, i've tried using a jquery/javascript 'for' loop to display the data, but cannot work out how to do it.
Any help would be appreciated, my code is below, minus the jquery/javascript loop.
<script type="text/javascript">
var options = { center: [], zoom: 0 };
var value = { latLng: [] };
@foreach (var item in Model)
{
<text>
options.center.push(@item.DisplayLatLonInMap);
value.latLng.push(@item.DisplayLatLonInMap);
</text>
}
$("#WeatherMapLocation").gmap3({
//defaults: {
// classes: {
// Marker: MarkerWithLabel
// }
//},
//{
map: { options: options },
marker: { values: [value],},
});
</script>
/====================================
Changed code to code below. but still no luck, i'm not that good at jquery etc
<script type="text/javascript">
$(document).ready(initialize);
var map;
var options = { center: [], zoom: 0 };
var value = { latLng: [] };
@foreach (var item in Model)
{
<text>
options.center.push(@item.DisplayLatLonInMap);
value.latLng.push(@item.DisplayLatLonInMap);
</text>
}
function initialize() {
var latlng = new google.maps.LatLng(42.354183,-71.065063);
var options = {
zoom: 0,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map($('#WeatherMapLocation')[0], options);
for( i = 0; i < value.length; i++) {
var latLng = new google.maps.LatLng(value);
var marker = new google.maps.Marker({
position: latLng,
map: map
});
}
}
Thanks in advance George