是否有提供/核心模塊來檢測用戶的物理位置(基於IP可能?)。D7 - 是否有檢測用戶位置的模塊?
我想最終做的是:1。 檢測用戶位置 2.計算距離用戶的當前位置到並連接到節點位置的數據(我的節點有位置數據) 3.過濾結果(即節目選擇節點)基於距離
任何方向將有所幫助。
我正在使用D7。
是否有提供/核心模塊來檢測用戶的物理位置(基於IP可能?)。D7 - 是否有檢測用戶位置的模塊?
我想最終做的是:1。 檢測用戶位置 2.計算距離用戶的當前位置到並連接到節點位置的數據(我的節點有位置數據) 3.過濾結果(即節目選擇節點)基於距離
任何方向將有所幫助。
我正在使用D7。
你正在尋找該模塊的IP地理定位的觀點https://drupal.org/project/ip_geoloc 你可能也想看看這個問題,回答:https://drupal.stackexchange.com/questions/54873/geofield-proximity-in-views
有兩個模塊(即我所知道的)提供的IP - 爲Drupal 7的位置檢測:
我認爲Location module將是你的下一站之後:
目前,它是唯一的模塊e爲實現基於位置的搜索提供必要的視圖集成,並且設計用於在用戶提供位置附近的地圖上查找點。
1-您可以使用jQuery和此awesome script檢索使用位置。使用的
實施例:
jQuery.getScript('http://www.geoplugin.net/javascript.gp', function()
{
$('#results').html("Your location is: " + geoplugin_countryName() + ",
" + geoplugin_region() + ", " + geoplugin_city());
});
-2-可以計算用戶位置和另一位置知道每個位置的緯度和經度之間的距離。
實施例:
jQuery.getScript('http://www.geoplugin.net/javascript.gp', function()
{
var source_longitude = 30.049999;
var source_latitude = 31.250000;
var user_longitude = geoplugin_longitude();
var user_latitude = geoplugin_latitude();
var earth_radius = 6371; // in Kilo Meters
var dLat = (source_latitude - user_latitude).toRad();
var dLon = (source_longitude - user_longitude).toRad();
source_latitude = source_latitude.toRad();
user_latitude = user_latitude.toRad();
var x = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(source_latitude) * Math.cos(user_latitude);
var y = 2 * Math.atan2(Math.sqrt(x), Math.sqrt(1 - x));
var distance = earth_radius * y;
});
3-要過濾的結果中,可以使用的距離和hook_node_access()來改變基於距離的節點查看權限。
希望這有助於...穆罕默德。
Smart IP module會將用戶的IP地址轉換爲經度和緯度座標。以下函數將返回兩對座標之間的球面距離(以英里爲單位)。
function _get_spherical_distance($s_pd, $s_ld, $f_pd, $f_ld) {
$s_pr = deg2rad($s_pd);
$f_pr = deg2rad($f_pd);
$lr = deg2rad($s_ld - $f_ld);
return 3960 * acos(sin($s_pr) * sin($f_pr) + cos($s_pr) * cos($f_pr) * cos($lr));
}
例如,亞特蘭大,GA(33.7489,-84.3879),以華盛頓州雷德蒙市(47.6739,-122.1214):
print _get_spherical_distance(33.7489, -84.3879, 47.6739, -122.1214);
輸出:
2170.4293537864
這是2170英里。如果您需要將地址轉換爲經度和緯度座標,則可以使用Google Geocoding API。
$address_string = "1600 Pennsylvania Avenue, Washington, DC 20500";
$geo_html = file_get_contents('http://maps.google.com/maps/geo?sensor=false&oe=utf8&output=csv&q='. urlencode($address_string));
print_r($geo_html);
輸出:
200,8,38.8987149,-77.0376555
這是逗號分隔的四個值中的字符串。第一個是HTTP status code。你應該看到200.第二個值是轉換的近似值accuracy。如果您要根據用戶與地址的距離來過濾內容,您可能需要的準確性值至少爲6。顯然,第三和第四個值是經度和緯度。
非常感謝您的代碼。我試了一下,我不認爲$。腳本獲取腳本 - 任何想法我可能做錯了什麼? jQuery的(文件)。就緒(函數(){ \t變種text_pass = '腳本獲取成功'; \t變種text_fail = '腳本下載失敗'; \t \t $ .getScript(的「http:// WWW。 geoplugin.net/javascript.gp」,函數() \t \t { \t \t \t警報(text_pass); \t \t} \t) }); – user1406716