Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery loop display muliple markers on google map
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Any help would be appreciated, my code is below, minus the jquery/javascript loop.</p> <pre><code>&lt;script type="text/javascript"&gt; var options = { center: [], zoom: 0 }; var value = { latLng: [] }; @foreach (var item in Model) { &lt;text&gt; options.center.push(@item.DisplayLatLonInMap); value.latLng.push(@item.DisplayLatLonInMap); &lt;/text&gt; } $("#WeatherMapLocation").gmap3({ //defaults: { // classes: { // Marker: MarkerWithLabel // } //}, //{ map: { options: options }, marker: { values: [value],}, }); &lt;/script&gt; </code></pre> <p>/====================================</p> <p>Changed code to code below. but still no luck, i'm not that good at jquery etc</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(initialize); var map; var options = { center: [], zoom: 0 }; var value = { latLng: [] }; @foreach (var item in Model) { &lt;text&gt; options.center.push(@item.DisplayLatLonInMap); value.latLng.push(@item.DisplayLatLonInMap); &lt;/text&gt; } 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 &lt; value.length; i++) { var latLng = new google.maps.LatLng(value); var marker = new google.maps.Marker({ position: latLng, map: map }); } } </code></pre> <p></p> <hr> <p>Thanks in advance George </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload