html5的地理定位功能getCurrentPosition还能用吗?

html-css013

html5的地理定位功能getCurrentPosition还能用吗?,第1张

能用,可以实现的,HTML5可以使用手机的GPS信息,利用百度等地图的开放API就可以了。\x0d\x0aHTML5中可以通过IP,WIFI信息,GPS,来实现地理定位,当然相关精度也是有所不同,所以如果要精确导航就得使用GPS信息。\x0d\x0a下面是一段HTML5结合百度地图API来获取位置的代码:\x0d\x0a\x0d\x0a当前定位地址:\x0d\x0a\x0d\x0avar map = new BMap.Map("allmap")\x0d\x0avar geolocation = new BMap.Geolocation()\x0d\x0ageolocation.getCurrentPosition(function(r){\x0d\x0aif(this.getStatus() == BMAP_STATUS_SUCCESS){\x0d\x0amap.panTo(r.point)\x0d\x0a//alert('您的位置:'+r.point.lng+','+r.point.lat)\x0d\x0avar pt = r.point\x0d\x0avar geoc = new BMap.Geocoder()\x0d\x0ageoc.getLocation(pt, function(rs){\x0d\x0avar addComp = rs.addressComponents\x0d\x0a//alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber)\x0d\x0a$("#du-gps").text(addComp.district+addComp.street+addComp.streetNumber)\x0d\x0a})\x0d\x0a}\x0d\x0aelse {\x0d\x0aalert('failed'+this.getStatus())\x0d\x0a}\x0d\x0a},{enableHighAccuracy: true})\x0d\x0a 回答于 2022-11-16

html5地理定位原理:

使用IP地址;基于Web的数据库;无线网络连接定位;三角测量;GPS技术;

来测量经度和纬度。(综合了所有技术)

地理定位的精确度,

有很多方法可以定位用户的地理位置,并且每种方法都有不同的精度。

桌面浏览器一般会使用WiFi(精确到20m)或者IP定位(只能精确到城市级别,并且有可能是假地址)。

移动装置一般会使用GPS(精确到10m并且只能在外部使用),

WiFi或GSM/CDMA网络信号定位(精确到1000m)。