Adding
Google Map in Your website
Step1: add following Script to the view
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
<script>
Step2: Create one div as
<div id="map" style="width: 300px; height:300px;"></div>
Step3: Add
following script in the view
<script type="text/javascript">
var address = '@ViewBag.address';
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address
},
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var initialLocation = new google.maps.LatLng(results[0].geometry.location.lat(),
results[0].geometry.location.lng());
var options = { zoom: 15, center: initialLocation, mapTypeId:
google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById("map"),
options);
var markerPos = new google.maps.LatLng(new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()));
var marker = new google.maps.Marker({ position: initialLocation, map: map,
title: "PC Pro Offices" });
}
else {
}
});
</script>
Step 4:done Run Your Application
No comments:
Post a Comment