Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 ?

share|improve this question
1  
Possible duplicate of gis.stackexchange.com/questions/21045/… –  Sunil Feb 27 '13 at 10:46
add comment

2 Answers

up vote 1 down vote accepted

this is my code

<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>

function search(){
    //alert('search start');
    var address = document.getElementById('address').value+",Kathmandu, Nepal";
    //alert(address);
    var geocode_url="http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address="

    //needs google api
    var geocoder = new GClientGeocoder();
    //geocoder.setBaseCountryCode('Nepal');
    var location = geocoder.getLatLng(address,
        function(point) {
            if (!point) {
                alert(address + " not found");
            } else {
                //alert("going to "+address);
                var loc = new OpenLayers.LonLat(point.x,point.y);
                map.setCenter(loc,3);
            }
        }
    );
}
share|improve this answer
add comment

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);                            
        }
    });
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.