Pages

Friday, April 26, 2013

ADD GOOGLE MAPS TO WEBSITE


Add this code to notepad and the save the extension as .html. Then execute the file in the browser....

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Show or Integrate Google Maps in asp.net webapplication</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var myLatlng= new google.maps.LatLng(-34.397, 150.644)
var mapOptions = {
center: myLatlng,
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP,
marker:true
};
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
}
</script>

</head>
<body onload="initialize()">
<form id="form1" runat="server">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</form>
</body>
</html>

Mark your place in the map:-


Inorder to mark your place in the map.. You need the follow the steps...
1.Go to Google Maps and Find latitude and longitude values of your place..
2. ex:-(-34.397, 150.644)
3.Then replace the values in the above script .. The map automatically shows the place



Add marker to your google map:-

var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Your Pointer or Marker Name"
});
marker.setMap(map);

Add this script to your file below this line 
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);

The total code give below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Show or Add markers to Google Maps in asp.net website</title>
<style type="text/css">
html { height100% }
body { height100%margin0padding0 }
#map_canvas { height100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var myLatlng= new google.maps.LatLng(-34.397, 150.644)
var mapOptions = {
center: myLatlng,
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP,
marker:true
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Your Location Address!"
});
marker.setMap(map);
}
</script>

</head>
<body onload="initialize()">
<form id="form1" runat="server">
<div id="map_canvas" style="width500pxheight300px"></div>
</form>
</body>
</html>


No comments:

Post a Comment