im having trouble with getting pushpins on my map. Im using Bing maps and i want to show some coordinates on it. i have followed a tutorial on youtube but still don't manage to make it.
The link is here https://www.youtube.com/watch?v=uVeuib8_MWw&t=2s
So this is what i got! In my class model i got
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Map.Models
{
public class Locations
{
public string latitude { get; set;}
public string longitude { get; set;}
public Locations(string latitude, string longitude)
{
this.latitude = latitude;
this.longitude = longitude;
}
}
}
In my controller i have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Map.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult GetLocations()
{
var locations = new List<Models.Locations>()
{
new Models.Locations("12.505353","55.335292"),
new Models.Locations("13.505353","55.485292"),
new Models.Locations("13.655353","55.665292")
};
return Json(locations, JsonRequestBehavior.AllowGet);
}
}
}
And at the end its the view. Here is the map aswell and the pushpins.
@{
ViewBag.Title = "Home Page";
}
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
$(document).ready(function () {
var map = null;
function LoadMap() {
map = new Microsoft.Maps.Map(
document.getElementById('myMap'),
{
credentials: "Bing map key"
});
}
LoadMap();
$('#btnShowLocations').click(function () {
var url = "/Home/GetLocations";
$.getJSON(url, null, function (data) {
$.each(data, function (index, LocationData) {
var pushpin = new Microsoft.Maps.pushpin(map.getCenter(), null);
pushpin.setLocation(new Microsoft.Maps.Location(
LocationData.latitude,
LocationData.longitude));
map.entities.push(pushpin);
map.setView({
zoom: 4, center: new Microsoft.Maps.Location(23.505353, 78.485292)
});
});
});
});
});
</script>
<h2>Bing Map integration in ASP.NET</h2>
<input type="button" id="btnShowLocations" value ="Show All Locations" />
<div id="myMap" style="position:relative; width:600px; height:600px;">
</div>
The map is working and i get no errors. My problem is that when i press the button nothing happens. What i want is that when the button is pressed there should be 3 pushpins on the given coordinates.
Thanks so very much for reading! i hope i can get it to work!