I want to render a KML file in google maps from my asp.net MVC 3 app.
From Google Maps JavaScript API V3, I'm using KmlLayer('url') to render the kml in google maps. I have read that kml file needs to be in a publicly accessible server. I could render the kml file locally with third party javascripts but they can be prone to errors. (Loading a local .kml file using google maps?)
The kml files I want to render are stored in a SQL server database as byte arrays. So for one Kml file I have to write the byte array into a path with kml extension. I have done this with File.WriteAllBytes(path, byte), where path = local path and byte = byte array from Database. THis is done in the Controller of MVC app. This is the code:
public ActionResult MapView(int id)
{
Incident inc = db.Incidents.Find(id);
if (inc.IncidentDatas.Count != 0)
{
ViewBag.ListKmlUrls = kmlFileStore(inc);
}
return View(inc);
}
public List<string> kmlFileStore(Incident inc)
{
List<string> listKmlUrls = new List<string>();
// Specify a "currently active folder"
string activeDir = @"c:\incident" + inc.incId + @"\incidentData";
//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, "kmlFiles");
// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);
String url;
foreach(var d in inc.IncidentDatas) {
url = @"c:\incident" + inc.incId + @"\incidentData\kmlFiles\" + d.id + ".kml";
//dataContent is byte[]
System.IO.File.WriteAllBytes(url, d.dataContent);
listKmlUrls.Add(url);
}
return listKmlUrls;
}
The idea is the view will access the list of urls through viewbag to pass urls to javascript method KmlLayer(...). But the urls here are only local paths.
So how can the MVC app store the kml file to a publicly accessible server so that it can pass a url to KmlLayer(...)? This would have to be done programmatically.
I'm currently accessing my MVC app and database from localhost. I have a static Ip and name. I would also like to publish the app and database for online access. Not sure how to proceed, please give me some advice/guidance. Thanks.