Skip to content Skip to sidebar Skip to footer

Unable To Reverse Geocode From Marker Click

I wonder whether someone may be able to help me please. I'm trying to put together the reverse geocode functionality for this page, where the user clicks on a map marker and the re

Solution 1:

I've been through my code again, and realised it wsn't quite right.

The reverse geocode script should look like this:

(functionreversegeocode() {


            var lat = document.getElementById('findosgb36lat').value;
            var lng = document.getElementById('findosgb36lon').value;

            var latlng = new google.maps.LatLng(lat, lng);

            getAddress(latlng);

            returnfalse;
        }

    )

    functiongeocodePosition(pos) {
        geocoder.geocode({
            latLng: pos
        },

        function(responses) {
            if (responses && responses.length > 0) {
                updateMarkerAddress(responses[0].formatted_address);
            } else {
                updateMarkerAddress('Cannot determine address at this location.');
            }
        });
    }

    functionupdateMarkerAddress(str) {
        document.getElementById('address').value = str;
    }

    functiongetAddress(latlng) {

        if (!geocoder) {
            geocoder = new google.maps.Geocoder();
        }

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

            if (status == google.maps.GeocoderStatus.OK) {
// Looping through the resultfor (var i = 0; i < results.length; i++) {
if (results[0].formatted_address) {

                document.getElementById('address').value = results[0].formatted_address;
            }

    }
    }
    }
    )
    }

Post a Comment for "Unable To Reverse Geocode From Marker Click"