Google Maps Geocoding with OpenLayers – How to Use and Integrate

addressgeocodinggoogle mapsopenlayers-2

I'm making a Openlayers map with some shapefile and I have Google Maps base layer. I want to create a text area and a button. When I input a address and click the button, the map should show me the google maps address in the map. Can you help me please ?

Best Answer

Try the below code.

var geocoder = new google.maps.Geocoder();

geocoder.geocode({ 'address': address }, function (results, status) {

  if (status == google.maps.GeocoderStatus.OK) {
           console.log(results[0].geometry.location);                              
        }
        else {
             console.log("Geocoding failed: " + status);                            
        }
    });