Skip to content

ecomfe/saber-geo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

saber-geo Build Status

适合移动端的 GeoLocation 封装

Installation

通过 edp 引入模块:

edp import saber-geo

Usage

require( [ 'saber-geo' ], function( Geo ) {

	function onSuccess( position ) {
    	var coords = position.coords;
       	console.log( 'latitude,longitude: ', coords.latitude, coords.longitude);
    }
    
    function onError( error ) {
    	console.log( 'Error: ', error.code, error.message );
    }
	
	// 一次性获取
	Geo.get( onSuccess, onError );
    
    // 持续性获取
    var watchId = Geo.watch( onSuccess, onError );
    
    // 停止获取
    Geo.clear( watchId );

});

Methods

该部分是标准的 HTML5 Geolocation API 封装,在 require( 'saber-geo' ) 时加载。

get( onSuccess[, onError, options] )

一次性获取当前地理位置信息

Geo.get(
	function ( position ) {
    	console.info( 'Position: ', position );
	},
	function ( error ) {
		console.error( 'Error: ', error );
	}
);
  • onSuccess {Function} 成功回调,参数参考Position
  • onError {Function=} 错误回调,参数参考PositionError
  • options {Object=} 配置对象
    • highAcuracy {boolean=} 是否使用高精度
    • timeout {number=} 超时时长,单位毫秒
    • age {number=} 数据缓存时间,单位毫秒,为0时每次都执行新的检索

watch( onSuccess[, onError, options] )

持续性获取当前地理位置信息

Geo.watch(
	function ( position ) {
    	console.info( 'Position: ', position );
	},
	function ( error ) {
		console.error( 'Error: ', error );
	},
	{ timeout: 20000, age: 10000 }
);
  • onSuccess {Function} 成功回调,参数参考Position
  • onError {Function=} 错误回调,参数参考PositionError
  • options {Object=} 配置对象
    • highAcuracy {boolean=} 是否使用高精度
    • timeout {number=} 超时时长,单位毫秒
    • age {number=} 数据缓存时间,单位毫秒,为0时每次都执行新的检索

clear( watchId )

停止指定的位置监控。

var watchId = Geo.watch( ... );
Geo.clear( watchId );
  • watchId {number} watch方法返回的watchId

Optional Modules 可选模块

  • Object IP模块
    • require('saber-geo/ip')

IP

在线IP查询服务的扩展支持,需以 require( 'saber-geo/ip' ) 引入。

Methods

setup( options )

  • options {Object}
    • callback {string} 查询请求(JSOP)附带的callback参数的键值,默认为callback
    • provider {string} 查询服务的JSONP服务地址,默认为http://hendless.duapp.com/addr

find( callback )

查询当前IP信息

  • callback {Function} 回调函数
require( [ 'saber-geo/ip' ], function( IP ) {
	IP.find( function () {
    	console.info( 'IP Info: ', arguments );
	});
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published