1

私はグーグルマップAPIを使い始めています。また、ジオコードに問題があり、修正する時間を失いました。しかし、それでもうまくいきません。私の演習:テキストボックス内に住所を入力してから、「場所を検索」ボタンをクリックします。指定された住所に基づいて緯度と経度を取得するためにJavaScriptを使用しています。新しい「フォーム アクション」タグを追加しなければ、すべて問題ありません (struts2 フレームワークを使用しています)。次のようになります。

function codeAddress() {
    var address = document.getElementById("locationId").value;
    geocoder
            .geocode(
                    {
                        'address' : address
                    },
                    function(results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            map.setCenter(results[0].geometry.location);
                            document.getElementById('latId').value = results[0].geometry.location
                                    .lat().toFixed(15);
                            document.getElementById('lonId').value = results[0].geometry.location
                                    .lng().toFixed(15);
                        } else {
                            alert("Lat and long cannot be found.");
                        }
                    });
}

<s:form action="searchNearestLocation">
    <s:hidden name="latInput" id="latId" />
    <s:hidden name="lonInput" id="lonId" />
    <s:textfield name="locationName" id="locationId" />
    <s:submit value="Find Location" name="findLocation" onclick="codeAddress()" />
    <div id="googleMap" style="width: 500px; height: 380px;"></div>
</s:form>
4

1 に答える 1