0
即时通讯在我的地图上获取图钉时遇到问题。 即时通讯使用Bing地图,我想显示一些坐标。我在YouTube上跟随了一个教程,但仍然无法完成。必应地图与ASP.NET MVC 4.5集成
链接在这里https://www.youtube.com/watch?v=uVeuib8_MWw&t=2s
所以这是我得到了什么! 在我的类模型,我得到
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;
}
}
}
在我的控制,我有:
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);
}
}
}
,并在结束其观点。这里是地图以及图钉。
@{
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>
该地图工作,我没有得到任何错误。我的问题是,当我按下按钮什么都没有发生。我想要的是,当按下按钮时,应该在给定的坐标上有3个图钉。
非常感谢您的阅读!我希望我能得到它的工作!
当我用您的视图代码地图消失。我没有让地图脚本工作 ““ 非常感谢帮助我,我一直坚持这个很长一段时间! – pertjo
URL中有错误的回调函数名称。更正的代码示例。 – rbrundritt
仍然没有得到它的工作:/ – pertjo