Javascript 地理定位html5不适用于Oppo和荣誉Android手机
这是我用来构建谷歌地图的代码。80%的安卓手机都使用这一代码,但当地的手机制造商不支持这一代码,因为我无法在像OPPO这样的手机上获得坐标 我试过谷歌地理定位API,它没有给出精确的定位Javascript 地理定位html5不适用于Oppo和荣誉Android手机,javascript,android,html,cordova,geolocation,Javascript,Android,Html,Cordova,Geolocation,这是我用来构建谷歌地图的代码。80%的安卓手机都使用这一代码,但当地的手机制造商不支持这一代码,因为我无法在像OPPO这样的手机上获得坐标 我试过谷歌地理定位API,它没有给出精确的定位 函数inti(){ if(导航器.地理位置){ navigator.geolocation.getCurrentPosition(geolocationSuccess); backview=“views/home.html”; } } 函数写入地址(latLng){ var geocoder=new goog
函数inti(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(geolocationSuccess);
backview=“views/home.html”;
}
}
函数写入地址(latLng){
var geocoder=new google.maps.geocoder();
地理编码({
“位置”:latLng
},
功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
var rr=results[0]。格式化的\u地址;
var res=rr.split(“,”);
//警报(res[0]+“,“+res[1]+”,“+res[2]);
}否则
“无法检索您的地址”+”
”;
});
}
函数初始化(){
//检查器每秒观察一次位置,如果位置已修复,则不会刷新
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(geolocationSuccess,淋浴ROR);
}否则
警报(“您的设备不支持地理定位。”);
}
功能地理位置成功(位置){
var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
writeAddress(userLatLng)
变量myOptions={
缩放:15,
中心:userLatLng,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var mapObject=new google.maps.Map(document.getElementById(“googleMap”),myOptions);
var marker=new google.maps.marker({
map:mapObject,
职位:userLatLng
});
var sunCircle={
strokeColor:#7DB1E8“,
笔划不透明度:0.5,
冲程重量:2,
填充颜色:“7DB1E8”,
填充不透明度:0.25,
map:mapObject,
中心:userLatLng,
半径:200//米
};
var cityCircle=新的google.maps.Circle(太阳圈);
城市圆宾托(中心,标记);
}
功能错误(错误){
开关(错误代码){
案例1:
警报(“用户拒绝了地理定位请求”);
打破
案例2:
警报(“位置信息不可用。请确保位置处于打开状态”);
打破
案例3:
打破
案例4:
警报(“发生未知错误”);
打破
}
}
#谷歌地图{
宽度:100%;
高度:80vh;
}
找到我
用拳猛击
试试这个
<p><button onclick="geoFindMe()">Show my location</button></p>
<div id="out"></div>
显示我的位置
剧本
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);
}
函数geoFindMe(){
var输出=document.getElementById(“out”);
如果(!navigator.geolocation){
output.innerHTML=“您的浏览器不支持地理位置””;
返回;
}
功能成功(职位){
变量纬度=位置坐标纬度;
var经度=position.coords.longitude;
output.innerHTML='纬度为'+Latitude+'''”
经度为'+Latitude+'''”;
var img=新图像();
img.src=”https://maps.googleapis.com/maps/api/staticmap?center=“+纬度+”、“+经度+”&zoom=13&size=300x300&sensor=false”;
输出。追加子项(img);
}
函数错误(){
output.innerHTML=“无法检索您的位置”;
}
output.innerHTML=“定位…””;
navigator.geolocation.getCurrentPosition(成功,错误);
}
如果这不起作用,请使用cordova地理定位插件并尝试
尝试地理定位选项
结果将受到以下原因的影响:
- 移动网络工具包版本
- 移动设备的互联网速度
- 该设备具有清晰、不间断的天空视图。GPS正在监听来自多个卫星的微弱信号。这些信号可能部分或完全被建筑物、茂密的树叶、车顶等遮挡