Wednesday, 7 December 2011

Google Map integration to the site without api keys

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false" ></script>
<script type="text/javascript">
//<![CDATA[var geocoder;
var map;
function initialize() {
 geocoder = new google.maps.Geocoder();
 var latlng = new google.maps.LatLng(-34.397, 150.644);
 var myOptions = {
  zoom: 8,
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
 }
 map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
 
function codeAddress() {
//var address = document.getElementById("address").value;
var address = "Sydney, NSW";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
 map.setCenter(results[0].geometry.location);
 var marker = new google.maps.Marker({
 map: map,
 position: results[0].geometry.location
 });
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
 
//]]>
</script>
</head>
<script>
$(document).ready(function() {
 initialize();
 codeAddress();
});
</script>
<div id="map_canvas" style="width: 400px; height: 280px;"></div>


1 comment :

  1. I regard something really special in this internet site.

    ReplyDelete