2016-12-28 3 views
-1

私の入力にGoogleオートコンプリートのカスタムフォームがあります。場所を選択して送信をクリックすると、緯度と経度の値が位置の値で更新され、検索が行われます。提出する前にgoogle maps apiで緯度と経度を更新してください

私は値が更新されるまでフォームを停止する方法を見つけることができません。私はonchangeやkeyupのような異なるイベントを試みましたが、これはapiへの多くの呼び出しを行い、これに対する良い答えではありません。

function geocodeAddress(geocoder) { 
    var address = document.getElementById('autoc-input-maps').value; 
    geocoder.geocode({'address': address}, function(results, status) { 
    if (status === google.maps.GeocoderStatus.OK){ 
     marker = new google.maps.Marker({ 
     position: results[0].geometry.location 
     }); 
     jQuery("#lat").val(marker.position.lat()); 
     jQuery("#lng").val(marker.position.lng()); 

    } else { 
     console.log('Geocode was not successful for the following reason: ' + status); 
    } 
    }); 
} 

    function updatecords() { 
     var geocoder = new google.maps.Geocoder(); 
     geocodeAddress(geocoder); 
    } 

jQuery('#auto-search').submit(function() { 
    updatecords(); 
    return true; 
}); 

私も送信時にタイムアウトを設定しようとしました。

+0

座標が使用可能な場合は、ジオコーダーコールバック関数でフォームを送信する必要があります。 – geocodezip

答えて

0

これに似た別の質問がhereと尋ねられました。私はあなたがこの機能を使うことができると思う:

function pan() { 
     var panPoint = new google.maps.LatLng(document.getElementById("lat").value, document.getElementById("lng").value); 
     map.panTo(panPoint) 
    } 

これは役に立ちます!

関連する問題