Skip to content Skip to sidebar Skip to footer

Google Map Set Location?

I have this code that shows the current location as being specified in the 'LatLng' coordinates. But what I want is have have an input boxes, lets say 2 input boxes 'location from

Solution 1:

you should use geocoder for that

geocoder = new google.maps.Geocoder();      
var address = document.getElementById('address').value; //input box value
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
}
});  

Map Fiddle

Solution 2:

You may check the examples on this address: https://developers.google.com/maps/documentation/javascript/demogallery

Here you can find the answer for your question also more advanced tecqniques that you may need on further.

Greets!

Solution 3:

Maybe something like :

boxLat.value = map.getCenter().getLat() ;boxLng.value = map.getCenter().getLng() ;

Post a Comment for "Google Map Set Location?"