function Location() {};
Location.prototype.getLocation = function (callback) {
let options = {
enableHighAccuracy: true,
maximumAge: 1000
};
this.callback = Object.prototype.toString.call(callback) == "[object Function]" ?
callback :
function (address) {
alert(address.province + address.city);
console.log("getocation(callbackFunction) 可获得定位信息对象");
};
let self = this;
if (navigator.geolocation) {
//浏览器支持geolocation
navigator.geolocation.getCurrentPosition(function (position) {
//经度
let longitude = position.coords.longitude;
//纬度
let latitude = position.coords.latitude;
self.loadMapApi(longitude, latitude);
}, self.onError, options);
} else {
//浏览器不支持geolocation
}
};
Location.prototype.loadMapApi = function (longitude, latitude) {
let self = this;
let oHead = document.getElementsByTagName('HEAD').item(0);
原生js获取手机定位信息 geolocation
最新推荐文章于 2024-04-26 10:00:00 发布