Skip to content

Instantly share code, notes, and snippets.

@tobbbe
Created July 10, 2014 09:24
Show Gist options
  • Save tobbbe/4f1a01bb96fdbb719082 to your computer and use it in GitHub Desktop.
Save tobbbe/4f1a01bb96fdbb719082 to your computer and use it in GitHub Desktop.
google maps iframe
@{
var longitude = Location.Longitude.ToString() ?? null;
var latitude = Location.Latitude.ToString() ?? null;
var googlemapSource = "https://www.google.com/maps/embed/v1/";
if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude))
{
// map mode
googlemapSource += "place?";
// cordinates / adress (has to use a dot not comma...)
longitude = longitude.Replace(",", ".");
latitude = latitude.Replace(",", ".");
googlemapSource += "&q=" + longitude + "+" + latitude;
// zoom level
googlemapSource += "&zoom=" + "10";
}
else
{
// map mode
googlemapSource += "view?";
// default location
googlemapSource += "center=" + "39.60342576096072,2.9043215749999978";
// zoom level
googlemapSource += "&zoom=" + "8";
}
// API key
googlemapSource += "&key=" + "AIzaSyAVn6ea2iJcMq9Wp0pKGlr3RpA8SVK1MCM";
// map type: roadmap or satellite
googlemapSource += "&maptype=" + "roadmap";
}
<iframe
width="100%"
height="280"
frameborder="0"
style="border:0"
scrolling="no"
src="@googlemapSource"
></iframe>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment