This is what I did for my syte. I'm working on MVC, but maybe I'll help 
you. 

<script> function initMap() { var map = new 
> google.maps.Map(document.getElementById('map'), { zoom: 12, center: { lat: 
> 38.897725, lng: -77.032421 } }); var geocoder = new google.maps.Geocoder(); 
> document.getElementById('submit').addEventListener('click', function () { 
> geocodeAddress(geocoder, map); }); } function geocodeAddress(geocoder, 
> resultsMap) { var address = document.getElementById('address').value; 
> geocoder.geocode({ 'address': address }, function (results, status) { if 
> (status === 'OK') { resultsMap.setCenter(results[0].geometry.location); var 
> marker = new google.maps.Marker({ map: resultsMap, position: 
> results[0].geometry.location }); 
> $('#CityName').val(results[0].address_components[0].long_name); 
> $('#lat').val(results[0].geometry.location.lat); 
> $('#lng').val(results[0].geometry.location.lng); } else { alert('Geocode 
> was not successful for the following reason: ' + status); } }); } </script>
>


When the user clicks on search button the GeocodeAddress function is 
executed.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-maps-js-api-v3+unsubscr...@googlegroups.com.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
Visit this group at https://groups.google.com/group/google-maps-js-api-v3.
For more options, visit https://groups.google.com/d/optout.

Reply via email to