2014-08-28 340 views
0

如何使用google地圖根據手機mac地址或gps或塔位置查找當前位置。如何使用手機mac地址查找位置?

請讓我知道如果有任何HTML代碼示例

+0

到目前爲止您嘗試過的是什麼? – 2014-08-28 06:02:38

回答

1

用途看我的定位API,它將有助於每秒獲取當前位置。您只需存儲一個位置(服務器)並從另一個位置的經度中獲取。

var id, target, options; 

function success(pos) { 
    var crd = pos.coords; 

    if (target.latitude === crd.latitude && target.longitude === crd.longitude) { 
    console.log('Congratulations, you reached the target'); 
    navigator.geolocation.clearWatch(id); 
    } 
}; 

function error(err) { 
    console.warn('ERROR(' + err.code + '): ' + err.message); 
}; 

target = { 
    latitude : 0, 
    longitude: 0, 
} 

options = { 
    enableHighAccuracy: false, 
    timeout: 5000, 
    maximumAge: 0 
}; 

id = navigator.geolocation.watchPosition(success, error, options); 
1

您可以使用HTML5

The HTML Geolocation API is used to get the geographical position of a user. Since this can compromise user privacy, the position is not available unless the user approves it.

試試下面的代碼支持地理位置API

<!DOCTYPE html> 
<html> 
<body> 

<p id="demo">Click the button to get your position.</p> 

<button onclick="getLocation()">Try It</button> 

<div id="mapholder"></div> 

<script> 
var x = document.getElementById("demo"); 

function getLocation() { 
    if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition(showPosition, showError); 
    } else { 
     x.innerHTML = "Geolocation is not supported by this browser."; 
    } 
} 

function showPosition(position) { 
    var latlon = position.coords.latitude + "," + position.coords.longitude; 

    var img_url = "http://maps.googleapis.com/maps/api/staticmap?center=" 
    +latlon+"&zoom=14&size=400x300&sensor=false"; 
    document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>"; 
} 

function showError(error) { 
    switch(error.code) { 
     case error.PERMISSION_DENIED: 
      x.innerHTML = "User denied the request for Geolocation." 
      break; 
     case error.POSITION_UNAVAILABLE: 
      x.innerHTML = "Location information is unavailable." 
      break; 
     case error.TIMEOUT: 
      x.innerHTML = "The request to get user location timed out." 
      break; 
     case error.UNKNOWN_ERROR: 
      x.innerHTML = "An unknown error occurred." 
      break; 
    } 
} 
</script> 

</body> 
</html> 
+0

我得到這個錯誤:用戶拒絕了地理定位請求。 如何批准?我應該在哪裏給電話號碼? – Lemon 2015-02-16 10:15:49

+0

當您的瀏覽器請求使用設備位置的權限時,請點擊批准。 – Vivek 2015-02-16 10:18:23

+0

我jsut複製粘貼在記事本中並保存爲html。它並不是要求denny allo pop。但這不是我所要求的。我想跟蹤一些其他人基於這樣的mac地址或電話號碼。怎麼做。 – Lemon 2015-02-16 10:26:32