geolocation

Geolocation模块管理设备位置信息,用于获取地理位置信息,如经度、纬度等。通过plus.geolocation可获取设备位置管理对象。虽然W3C已经提供标准API获取位置信息,但在某些平台存在差异或未实现,为了保持各平台的统一性,定义此规范接口获取位置信息。

方法:

对象:

回调方法:

权限:

5+功能模块(permissions)

{
// ...
"permissions":{
	// ...
	"Geolocation": {
		"description": "位置信息"
	}
}
}
			

Position

JSON对象,设备位置信息数据

interface Position {
	readonly attribute Coordinates coords;
	readonly attribute String coordsType;
	readonly attribute Number timestamp;
	readonly attribute Address address;
	readonly attribute String addresses;
}
				

属性:

Address

JSON对象,地址信息

interface Address {
	readonly attribute String country;
	readonly attribute String province;
	readonly attribute String city;
	readonly attribute String district;
	readonly attribute String street;
	readonly attribute String streetNum;
	readonly attribute String poiName;
	readonly attribute String postalCode;
	readonly attribute String cityCode;
}			
				

属性:

Coordinates

JSON对象,地理坐标信息

interface Coordinates {
	readonly attribute double latitude;
	readonly attribute double longitude;
	readonly attribute double altitude;
	readonly attribute double accuracy;
	readonly attribute double altitudeAccuracy;
	readonly attribute double heading;
	readonly attribute double speed;
}			
				

属性:

PositionOptions

JSON对象,监听设备位置信息参数

属性:

GeolocationError

JSON对象,定位错误信息

interface GeolocationError {
	const Number PERMISSION_DENIED = 1;
	const Number POSITION_UNAVAILABLE = 2;
	const Number TIMEOUT = 3;
	const Number UNKNOWN_ERROR = 4;
	readonly attribute Number code;
	readonly attribute String message;
}			
				

属性:

GeolocationSuccessCallback

获取设备位置信息成功的回调函数

void onSuccess( position ) {
	// Get Position code.
}
				

参数:

返回值:

void : 无

GeolocationErrorCallback

获取设备位置信息失败的回调函数

function void onGeolocationError( GeolocationError error ) {
	// Handle error
	var code = error.code; // 错误编码
	var message = error.message; // 错误描述信息
}
				

参数:

返回值:

void : 无