<!DOCTYPE html>
<html>
<head>
<title>Geolocation API with Bing Maps</title>
<style type="text/css">
html
{
height: 100%;
}
body
{
height: 100%;
margin: 0px;
padding: 0px;
}
</style>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.js" type="text/javascript"></script>
<script src="modernizr-1.7.min.js" type="text/javascript"></script>
</head>
<body>
<div id="mapElement" style="width: 100%; height: 100%">
</div>
<script type="text/javascript">
var map = null;
var layer;
$(document).ready(function () {
if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(function (e) {
generateMap(e);
createLayer();
addPushPin();
});
}
else {
alert("No Geolocation support in your browser!");
}
});
function generateMap(e) {
map = new VEMap('mapElement');
var location = new VELatLong(e.coords.latitude, e.coords.longitude);
map.LoadMap(location, 10, VEMapStyle.Hybrid);
}
function createLayer() {
layer = new VEShapeLayer();
map.AddShapeLayer(layer);
}
function addPushPin() {
var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
shape.SetTitle('The Current Location');
layer.AddShape(shape);
}
</script>
</body>
</html>