<script type="text/javascript"> function initialize() { var mapOptions = { center: new google.maps.LatLng(58, 60), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); var input = document.getElementById('searchTextField'); var autocomplete = new google.maps.places.Autocomplete(input); autocomplete.bindTo('bounds', map); var infowindow = new google.maps.InfoWindow(); var marker = new google.maps.Marker({ map: map }); google.maps.event.addListener(autocomplete, 'place_changed', function() { infowindow.close(); var place = autocomplete.getPlace(); if (place.geometry.viewport) { map.fitBounds(place.geometry.viewport); } else { map.setCenter(place.geometry.location); map.setZoom(17); </script>
and ur define ur HTML components similar to ...
<input id="searchTextField" type="text" size="50"> <div id="map_canvas"></div>
add the following line of line to the heading. <script src="//maps.googleapis.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>
It will work for u like magic ...
Luck
source share