2012-05-02 151 views
0

我有一個經度和緯度查找與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調用,存儲搜索的經度和緯度到數據庫中,然後提交表單,並與存儲的經度和緯度查詢數據庫。不知怎的,我覺得必須有一個更有效的方式。

謝謝! 斯科特

+2

您可以嘗試在PHP中使用捲曲,你將擁有所有信息之前,頁面加載http://php.net/manual/en/book.curl.php – YamahaSY

回答

相關問題