我认为,当我安装 Jmelosegui.Mvc.Googlemap 时,它确实在某处搞砸了。我收到关于版本不匹配和各种奇怪事情的错误。我已经回退到我的代码的以前版本(不是备份很好)并设法让我的地图显示。我
我的解决方案
控制器
// -------------------- Display a Map of the Battlefield showing the location of all of the monuments that have been entered to the DB -------------------------------------------------
public ActionResult MapMonuments(string battleRecID)
{
var monumentMap = from s in db.Monuments
where ((s.MonumentBattleRecID == battleRecID) &&
(s.MonumentStatus == "A"))
select s;
ViewBag.avgLat = monumentMap.Average(s => s.MonumentLocationLat);
ViewBag.avgLong = monumentMap.Average(s => s.MonumentLocationLong);
return PartialView(monumentMap.ToList());
}
查看
@model IEnumerable<CWBFM.Models.Monument>
// avgLat = the average of all of the latitudes
// avgLong = the average of all of the longitudes
Int_Map("@ViewBag.avgLat", "@ViewBag.avgLong");
//所有的乐趣都发生在哪里
function Int_Map(avgLat, avgLong) {
var latlng = new google.maps.LatLng(avgLat, avgLong);
// These are options that set initial zoom level, where the map is centered globally to start, and the type of map to show
var mapOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
panControl: true,
zoomControl: true,
streetViewControl: true,
mapTypeControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
}
}
// This makes the div with id "map_canvas" a google map
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
// place a marker on the map for each monument
@foreach (var place in Model) {
<text>
var myLatLng = new google.maps.LatLng("@place.MonumentLocationLat", "@place.MonumentLocationLong");
var markerTitle = "@place.MonumentName"; // input the monuments name from the database
var URL = "http://cwbfm.org/Monument/MonumentDetails/" + "@place.MonumentID"; // create the url to link to the monuments detail page
// set the marker icon based on the Allegiance
switch ("@place.MonumentAllegiance") {
case "B":
var image = 'http://maps.google.com/mapfiles/kml/paddle/grn-circle.png';
break;
case "C":
var image = 'http://maps.google.com/mapfiles/kml/paddle/red-circle.png';
break;
case "U":
var image = 'http://maps.google.com/mapfiles/kml/paddle/blu-circle.png';
break;
default:
var image = 'http://maps.google.com/mapfiles/kml/paddle/ylw-circle.png';
}
var myMarker = new google.maps.Marker({
position: myLatLng,
icon: image,
title: markerTitle,
url: URL,
map: map
});
// on click, go to the monuments detail page
google.maps.event.addListener(myMarker, "click", function () {
window.location.href = this.url;
});
</text>
} return
}
这对我来说很好。