Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe that you are facing an issue in converting the Model to javascript object.</p> <p>Below I separated the Index view from the part which actually fetches the data</p> <ol> <li><p><code>Index</code> returns just your page which would then make an ajax call for fetching locations.</p></li> <li><p><code>GetLocations</code> returns a JSON object array of locations to be used for rendering positions on Bing Maps</p></li> </ol> <p><strong>Changes to Controller</strong></p> <pre><code> public ActionResult Index() { return View(); } public ActionResult GetLocations() { List&lt;Models.Locations&gt; locations = new List&lt;Models.Locations&gt;() { new Models.Locations("55.473746", "8.447411") , new Models.Locations("55.504991", "8.443698"), new Models.Locations("55.468283", "8.438"), new Models.Locations("55.468283", "8.438"), new Models.Locations("55.468283", "8.438"), new Models.Locations("55.498978", "8.40002") } return JsonResult(locations); } </code></pre> <p><strong>Javascript Changes</strong></p> <p>Changed <code>showPosition</code> which now makes an ajax request fetching JSON location list and pushing it onto the map. Note : <em>You might have to refactor rest of your javascript just a bit.</em></p> <pre><code> function showPosition(position) { //display position var location = position.coords; map.setView({ zoom: 10, center: new Microsoft.Maps.Location(location.latitude, location.longitude) }); $.ajax({ url : 'getlocations' , type : 'json' }).done(function(locationsArray){ alert(locationsArray); var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), null); $.each(locationsArray, function(index,location) { map.entities.push(pushpin); pushpin.setLocation(new Microsoft.Maps.Location( location.latitude, location.longitude)); }); }; } </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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