Search Address in Google Map using JavaScript Code in HTML

  1. <html>  
  2.   
  3.     <head>  
  4.         <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />  
  5.         <meta http-equiv="content-type" content="text/html; charset=UTF-8" />  
  6.         <title>Geo Code </title>  
  7.         <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>  
  8.         <script type="text/javascript">  
  9.         var geocoder;  
  10.         var map;  
  11.         var address = "New Delhi";  
  12.   
  13.         function initialize()  
  14.         {  
  15.             geocoder = new google.maps.Geocoder();  
  16.             var latlng = new google.maps.LatLng(-34.397, 150.644);  
  17.             var myOptions = {  
  18.                 zoom: 14,  
  19.                 center: latlng,  
  20.                 mapTypeControl: true,  
  21.                 mapTypeControlOptions:  
  22.                 {  
  23.                     style: google.maps.MapTypeControlStyle.DROPDOWN_MENU  
  24.                 },  
  25.                 navigationControl: true,  
  26.                 mapTypeId: google.maps.MapTypeId.ROADMAP  
  27.             };  
  28.             map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);  
  29.             if(geocoder)  
  30.             {  
  31.                 geocoder.geocode(  
  32.                 {  
  33.                     'address': address  
  34.                 }, function (results, status)  
  35.                 {  
  36.                     if(status == google.maps.GeocoderStatus.OK)  
  37.                     {  
  38.                         if(status != google.maps.GeocoderStatus.ZERO_RESULTS)  
  39.                         {  
  40.                             map.setCenter(results[0].geometry.location);  
  41.                             var infowindow = new google.maps.InfoWindow(  
  42.                             {  
  43.                                 content: '<b>' + address + '</b>',  
  44.                                 size: new google.maps.Size(150, 50)  
  45.                             });  
  46.                             var marker = new google.maps.Marker(  
  47.                             {  
  48.                                 position: results[0].geometry.location,  
  49.                                 map: map,  
  50.                                 title: address  
  51.                             });  
  52.                             google.maps.event.addListener(marker, 'click', function ()  
  53.                             {  
  54.                                 infowindow.open(map, marker);  
  55.                             });  
  56.                         }  
  57.                         else  
  58.                         {  
  59.                             alert("No results found");  
  60.                         }  
  61.                     }  
  62.                     else  
  63.                     {  
  64.                         alert("Geocode was not successful for the following reason: " + status);  
  65.                     }  
  66.                 });  
  67.             }  
  68.         }  
  69.         </script>  
  70.     </head>  
  71.   
  72.     <body style="margin:0px; padding:0px;" onload="initialize()">  
  73.         <div id="map_canvas" style="width:100%; height:100%">  
  74.     </body>  
  75.   
  76. </html>   
Address search, search address using JavaScript ,search address on Google map, search dynamic address in Google map, search Geocode.