Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad multiple Bing Maps pins from Razor model
    primarykey
    data
    text
    <p>I'm new at using javascript and ASP.Net MVC 4. But i have tried to add multiple pins in the bing map, from the Razor @Model. i have tried:</p> <pre><code>@model IEnumerable&lt;Foundation3SinglePageRWD.Models.Locations&gt; &lt;div id="map" style="height: 800px; width: 100%"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; $(function () { var map = null; var location = null; function loadMap() { // initialize the map map = new Microsoft.Maps.Map(document.getElementById('map'), { credentials: "My Bing Map Key", enableSearchLogo: false }); } function showPosition(position) { function showPosition(position) { //display position var location = position.coords; map.setView({ zoom: 10, center: new Microsoft.Maps.Location(location.latitude, location.longitude) }); //var pushpinOptions = { icon: virtualPath + '/Content/images/foundation/orbit/Push.png' }; var test = '@model'; alert(test); var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), null); for (var i = 0; i &lt; test.l.length; i++) { map.entities.push(pushpin); pushpin.setLocation(new Microsoft.Maps.Location(test.latitude, test.longitude)); }; } } function positionError(position) { alert("Error getting position. Code: " + position.code); } loadMap(); navigator.geolocation.getCurrentPosition(showPosition, positionError); }); &lt;/script&gt; </code></pre> <p>The Controller:</p> <pre><code> public ActionResult Index() { List&lt;Models.Locations&gt; loc = new List&lt;Models.Locations&gt;(); Models.Locations temp = new Models.Locations("55.473746", "8.447411"); loc.Add(temp); Models.Locations temp1 = new Models.Locations("55.504991", "8.443698"); loc.Add(temp1); Models.Locations temp2 = new Models.Locations("55.468283", "8.438"); loc.Add(temp2); Models.Locations temp3 = new Models.Locations("55.498978", "8.40002"); loc.Add(temp3); return View(loc); } </code></pre> <p>and finally the Model:</p> <pre><code> public class Locations { public string latitude { get; set; } public string longitude { get; set; } public List&lt;Locations&gt; Loca { get; set; } public Locations(string latitude, string longitude) { this.latitude = latitude; this.longitude = longitude; } } </code></pre>
    singulars
    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. 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