To implement the Google Maps in Asp.Net with Demo you need to follow the below steps :
Step1 :
Create a new Asp.net website in Visual Studio and write the following html code in the design part of the Default.aspx page.
Default.aspx Code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>Demo: Geolocation</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
function success(position) {
var s = document.querySelector('#status');
if (s.className == 'success') {
return;
}
s.innerHTML = "found you!";
s.className = 'success';
var mapcanvas = document.createElement('div');
mapcanvas.id = 'mapcanvas';
mapcanvas.style.height = '400px';
mapcanvas.style.width = '560px';
document.querySelector('article').appendChild(mapcanvas);
var latlng = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL },
mapTypeId:
google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapcanvas"),
myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "You are here! (at least within a " + position.coords.accuracy + " meter radius)"
});
}
function error(msg) {
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
</script>
</head>
<body>
<section id="wrapper">
<header>
<h1>geolocation</h1>
</header>
<meta name="viewport" content="width=620" />
<article>
<p>Finding your location: <span id="status">checking....</span></p>
</article>
</section>
</body>
</html>
OutPut :
Step2 : Now build the solution and debug it for output.
Step2 : Now build the solution and debug it for output.
Thank you...:)
ReplyDelete