我正在使用 Spring MVC 开发移动 Web 应用程序。对于地理定位,我从 here 获取代码
我在该网站上通过手机运行了演示,它要求位置许可,在 jsfiddle 演示上也是如此,并且它正在工作。如果我没有启用 GPS,我会收到“无法检索您的位置”。
但是在我的应用程序上,我立即收到上述消息,而无需请求许可(还从 Chrome 中删除了所有被阻止的应用程序)。
在 PC 上,地理定位可以通过我的应用程序正常工作,但在我的手机上则不行。可能是什么问题?意思是……为什么地理定位无法通过我的应用程序在我的手机上工作,但可以在其他网站上工作。在我的手机上,直接转到 error() 函数。 也许我必须在配置文件中进行一些更改,或者我不知道..
LE:在另外 2 台设备上进行了测试,输出相同:无法检索您的位置...(启用 GPS)
LE2:我检查了错误代码。我的权限被拒绝 This is the Fiddle
<p><button onclick="geoFindMe()">Show my location</button></p>
<div id="out"></div>
//Javascript
function geoFindMe() {
var output = document.getElementById("out");
if (!navigator.geolocation){
output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
return;
}
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';
var img = new Image();
img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";
output.appendChild(img);
};
function error() {
output.innerHTML = "Unable to retrieve your location";
};
output.innerHTML = "<p>Locating…</p>";
navigator.geolocation.getCurrentPosition(success, error);
}
最佳答案
您可以检查此代码, https://github.com/makubex88/MobileHTML5CodeCamp/blob/master/mobilehtml5.html
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 + "'>";
}
关于javascript - Html 地理定位在我的移动网络应用程序上不起作用 | Spring MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37640197/