I'm trying to combine google's geocoding service with openlayers. So when a user types an address and hits enter, map zooms there and renders a simple point. I edited my code according to the previous link. Does not work. I'm using a vector layer as basic (comes from Geoserver/PostGIS), a google's layer as second basic. I also added a simple vector layer to render the adrress's point. Do I have to bind google's layer and geocoding service somehow?
Here is my code. Can you spot what's wrong?
var geocoder;
function codeAddress()
{alert ('inside function');//works
var address = document.getElementById("address").value;
//tell to user, he did not type anything
if (address==""){document.getElementById("geocodMsgG").innerHTML = "You gave no input";}
else{
alert(address);//works
geocoder.geocode( { 'address': address}, function(results, status)
{alert(status);//not work
if (status == google.maps.GeocoderStatus.OK) {
alert('inside 2 function');//not work
alert(results[0].geometry.location);//not work
//create a geometry point
pointgc = new OpenLayers.Geometry.Point(results[0].geometry.location);
//create a feature point
feature_point_gc = new OpenLayers.Feature.Vector(pointgc);
//lfl contains bounds that i set earlier in my code
if (lfl.containsLonLat(results[0].geometry.location)){
//render the point on the layer named geoco
geoco.addFeatures([feature_point_gc]);
geoco.refresh({force:true});
//zoom there
map.setCenter(results[0].geometry.location);
}
//if point is not inside the bounds (lfl) then dont add - print msg to user
else{document.getElementById("geocodMsgG").innerHTML = "out of bounds";}
}
//refers to the second if(geocoding's status)
else {document.getElementById("geocodMsgG").innerHTML = "error";}
});//geocode
}//major else (if address empty or not)
}//function