1
從谷歌標準的地理位置代碼在移動瀏覽器工作(Android版Chrome瀏覽器,Android標準瀏覽器):谷歌地理位置doesn't工作
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Reverse Geocoding</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, errorFunction, {enableHighAccuracy: true});
}
//Get the latitude and the longitude;
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
codeLatLng(lat, lng)
}
function errorFunction(){
alert("Geocoder failed");
}
function initialize() {
geocoder = new google.maps.Geocoder();
}
function codeLatLng(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results)
if (results[1]) {
//formatted address
alert(results[2].address_components[0].long_name)
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
</script>
</head>
<body onload="initialize()">
</body>
</html>
但在桌面瀏覽器正常工作...爲什麼?我確信代碼已經在幾天前工作了。我沒有改變任何東西。有可能谷歌已經改變了他們的代碼中的東西?
編輯:這對我來說很重要,以獲得與GPS,WLAN和位置!移動網絡
是的,我明白了,現在它可以與GPS傳感器一起使用,並且只有當我打開GPS時。但必須有可能通過WLAN或移動信號獲取位置。 – m1crdy
@ m1crdy地理位置完全取決於用戶。你無法強迫它,對。這就是爲什麼如果你在桌面瀏覽器中檢查,它會顯示一個共享當前位置的彈出窗口。而在移動中它使用GPS跟蹤器。無線或移動信號。希望你明白我的觀點。 – Praveen
,但如果用戶使用移動信號或WiFi激活位置,則必須可以在沒有GPS的情況下找到用戶。例如。 Facebook應用程序完全是這樣! – m1crdy