簡體   English   中英

Google Geocoder映射經度和緯度查詢

[英]Geocoder google maps longitude and latitude lookup

我有一個經度和緯度查詢,可以很好地與ajax調用一起工作,如下所示:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

var geocoder = new google.maps.Geocoder();
var address = "<?php echo addslashes($_POST['street'].' '.$_POST['house_number'].', '.$_POST['postal_code'].', '.$_POST['city'].', '.$_POST['country']); ?>";

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

    if (status == google.maps.GeocoderStatus.OK) {

        var latitude = results[0].geometry.location.lat();
        var longitude = results[0].geometry.location.lng();
        var request_key = '<?php echo $ajax_request_key; ?>';
        var url = '<?php echo $settings['base_url'].'/site/templates/ajax/add_vacancy_latitude_and_longitude.php?vacancy_id='.$_POST['vacancy_id']; ?>';

        //add longitude and latitude to database
        $.post(url, { this_latitude:latitude, this_longitude:longitude, this_request_key:request_key }, function(data) {  });

    }

}); 
</script>

但這僅適用於ajax調用。 有沒有辦法可以處理http請求,所以我可以立即查詢mysql數據庫中的空缺,而無需進行第二次頁面加載(例如,我有一個搜索表單,用戶可以在其中輸入郵政編碼,我想提交后立即將其郵政編碼的經度和緯度與數據庫進行比較。

我現在可以想到的方法是阻止使用jquery提交並進行ajax調用,將用於搜索的經度和緯度存儲到數據庫中,然后提交表單並使用存儲的經度和緯度查詢數據庫。 我以某種方式認為必須有一種更有效的方法。

謝謝! 史考特

嗨,斯科特,有一種使用卷曲的有效方法。

您可以像這樣直接撥打http

http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false

您必須將2個參數傳遞給url 1.地址2. sensor

請享用!

  • 達塔

暫無
暫無

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

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