Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created March 15, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deanhume/2a2c88a6f963b6eb629dfa94e0c72d6e to your computer and use it in GitHub Desktop.
Save deanhume/2a2c88a6f963b6eb629dfa94e0c72d6e to your computer and use it in GitHub Desktop.
DrawMap
/// <summary>
/// Draws the map.
/// </summary>
/// <param name="helper">The helper.</param>
/// <param name="key">The key.</param>
/// <param name="jsonUrl">The json URL.</param>
/// <param name="mapWidth">Width of the map.</param>
/// <param name="mapHeight">Height of the map.</param>
/// <returns>The html of the map.</returns>
public static string DrawMap(this HtmlHelper helper, string key, string jsonUrl, string mapWidth, string mapHeight)
{
StringBuilder mapHtml = new StringBuilder();
// Google Maps API Link
mapHtml.Append("<script src=\\"http://maps.google.com/maps");
mapHtml.Append("?file=api&amp;v=2&amp;sensor=false&amp;key=");
mapHtml.Append(key);
mapHtml.Append("\\" type=\\"text/javascript\\"></script>");
// Hidden value
mapHtml.Append("<input type=\\"hidden\\" ");
mapHtml.Append("id=\\"MarkerUrl\\" value=\\"");
mapHtml.Append(jsonUrl);
mapHtml.Append("\\" />");
// Map Div
mapHtml.Append("<div id=\\"map\\" style=\\"width: ");
mapHtml.Append(mapWidth);
mapHtml.Append("px; height: ");
mapHtml.Append(mapHeight);
mapHtml.Append("px\\"></div>");
// Maps javascript file
mapHtml.Append("<script type=\\"text/javascript\\" ");
mapHtml.Append("src=\\"/Content/GoogleMapping.js\\"></script>");
return mapHtml.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment