I have a problem in my MVC4 project in visual studio 2012. I build a backoffice in symfony2 and there i can display google maps with polygons loaded from a kml file.
Now i am trying to do the same thing in asp.net (C#)... But my code doesn't seem able to access the kml-file.
I am not using the Model View Controller system to acces my file, and maybe that is the problem...
i made a directory in my project named 'Kmls' and i pasted my kml in there (1.kml, 2.kml, ...) this is my code of my view:
@model IEnumerable<SocialGeo.Models.district>
@{
ViewBag.Title = "Index";
}
<h3>Choose a district first</h3>
<ul class="allDistricts" data-kml="">
@foreach (var item in Model) {
@Html.ActionLink(item.district_name, "DistrictNews", new { id=item.district_id})
}
</ul>
<script type="text/javascript">
$(document).ready(function () {
var myOptions = {
center: new google.maps.LatLng(51.087633, 3.711569),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var paths =
{
imagePath: "@Url.Content("~/Kmls/10.kml")"
}
$("section").append('<div class="mapscanvas" id="map_canvas' + 0 + '"></div>');
map = new google.maps.Map(document.getElementById("map_canvas" + 0), myOptions);
geoXml = geoXML3.parser({ map: map, singleInfoWindow: true, zoom: false });
//var jej = @HttpContext.Current.Server.MapPath("~/Kmls/10.kml")
geoXml.parse(paths.imagePath);
});
</script>
When i run the application (debugging) in firefox i get the following error in console:
GET: http://localhost:53760/Kmls/10.kml 404NotFound
HTTP error 404 retrieving /Kmls/10.kml in polys.js (line 990)
Unable to retrieve /Kmls/10.kml
I see the map, but not the polygon that I need.
Do I have to use a controller for this too? this is my controlleraction that is being called:
public ActionResult Index()
{
var districts = db.districts.Include(d => d.city);
return View(districts.ToList());
}
Any help would be highly appreciated!