簡體   English   中英

無法從標記撤消地址解析

[英]Unable to Reverse Geocode From Marker Click

我想知道是否有人可以幫助我。

我正在嘗試為該頁面組合反向地理編碼功能,其中用戶單擊地圖標記,然后執行反向地理編碼,並使用輸出地址填充文本字段。

從本網站收到一些很好的建議后,我以為我已經解決了該問題,但似乎無法解決我遇到的問題。

我可以使用標記lat和lng坐標填充文本字段,但是我只能從反向地址解析中獲取任何信息。

我已經使用JS Fiddle遍歷了代碼,並且Javscript沒有任何問題,而且我一直在看一些在線教程,但是我只是不知道我要去哪里錯了。

我只是想知道是否有人可以看看這個,讓我知道我要去哪里了。

非常感謝

我再次檢查了我的代碼,發現它不太正確。

反向地址解析腳本應如下所示:

(function reversegeocode() {


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

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

            getAddress(latlng);

            return false;
        }

    )

    function geocodePosition(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.');
            }
        });
    }

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

    function getAddress(latlng) {

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

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

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

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

    }
    }
    }
    )
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM