Reverse Geocoding Code

后端 未结 2 1846
名媛妹妹
名媛妹妹 2020-12-29 09:13

I\'ve been working on putting together the Javavscript code for Reverse Geocoding in Google maps. I thought I\'d solved all the issues I had, but I\'m still having problems.

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 09:51

    This is the short version of Khepri's (thank you!) Code

    function getReverseGeocodingData(lat, lng) {
        var latlng = new google.maps.LatLng(lat, lng);
        // This is making the Geocode request
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'latLng': latlng }, function (results, status) {
            if (status !== google.maps.GeocoderStatus.OK) {
                alert(status);
            }
            // This is checking to see if the Geoeode Status is OK before proceeding
            if (status == google.maps.GeocoderStatus.OK) {
                console.log(results);
                var address = (results[0].formatted_address);
            }
        });
    }
    

    this is also needed, do not forget in head:

    
    

提交回复
热议问题