NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[TOC] ## 概述 语法 ``` interface Geolocation { clearWatch(watchId: number): void; getCurrentPosition(successCallback: PositionCallback, errorCallback?: PositionErrorCallback | null, options?: PositionOptions): void; watchPosition(successCallback: PositionCallback, errorCallback?: PositionErrorCallback | null, options?: PositionOptions): number; } declare var Geolocation: { prototype: Geolocation; new(): Geolocation; }; ``` ## 实例 ### 获取位置 ``` navigator.geolocation.getCurrentPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude); }); ``` ### 监听位置 响应定位数据发生的变更(设备发生了移动,或获取到了更高精度的地理位置信息) ``` var watchID = navigator.geolocation.watchPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude); }); ```