实例1: convert
import com.amap.api.location.CoordinateConverter; //导入依赖的package包/类
private void convert() {
try{
//初始化坐标转换类
CoordinateConverter converter = new CoordinateConverter(
getApplicationContext());
/**
* 设置坐标来源,这里使用百度坐标作为示例
* 可选的来源包括:
* <li>CoordType.BAIDU : 百度坐标
* <li>CoordType.MAPBAR : 图吧坐标
* <li>CoordType.MAPABC : 图盟坐标
* <li>CoordType.SOSOMAP : 搜搜坐标
* <li>CoordType.ALIYUN : 阿里云坐标
* <li>CoordType.GOOGLE : 谷歌坐标
* <li>CoordType.GPS : GPS坐标
*/
converter.from(CoordType.BAIDU);
//设置需要转换的坐标
converter.coord(examplePoint);
//转换成高德坐标
DPoint destPoint = converter.convert();
if(null != destPoint){
tvConvertReult.setText("转换后坐标(经度、纬度):" + destPoint.getLongitude() + "," + destPoint.getLatitude());
} else {
Toast.makeText(getApplicationContext(), "坐标转换失败", Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
Toast.makeText(getApplicationContext(), "坐标转换失败", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
实例2: checkIsAvaliable
import com.amap.api.location.CoordinateConverter; //导入依赖的package包/类
private void checkIsAvaliable(){
//初始化坐标工具类
CoordinateConverter converter = new CoordinateConverter(
getApplicationContext());
//判断是否高德地图可用的坐标
boolean result = converter.isAMapDataAvailable(examplePoint.getLatitude(), examplePoint.getLongitude());
if(result){
tvCheckReult.setText("该坐标是高德地图可用坐标");
} else {
tvCheckReult.setText("该坐标不能用于高德地图");
}
}
实例3: amapLocationToObject
import com.amap.api.location.CoordinateConverter; //导入依赖的package包/类
private WritableMap amapLocationToObject(AMapLocation amapLocation) {
WritableMap map = Arguments.createMap();
Integer errorCode = amapLocation.getErrorCode();
if (errorCode > 0) {
map.putInt("errorCode", errorCode);
map.putString("errorInfo", amapLocation.getErrorInfo());
} else {
Double latitude = amapLocation.getLatitude();
Double longitude = amapLocation.getLongitude();
if (!needMars) {
try {
CoordinateConverter converter = new CoordinateConverter(mReactContext);
//返回true代表当前位置在大陆、港澳地区,反之不在。
boolean isAMapDataAvailable = converter.isAMapDataAvailable(latitude,longitude);
if (isAMapDataAvailable) {
// 在中国境内,火星了
double[] deltas = delta(latitude, longitude);
latitude = latitude - deltas[0];
longitude = longitude - deltas[1];
}
} catch (Exception ex) {
return null;
}
}
map.putInt("locationType", amapLocation.getLocationType());
map.putDouble("latitude", latitude);
map.putDouble("longitude", longitude);
if (needDetail) {
// GPS Only
map.putDouble("accuracy", amapLocation.getAccuracy());
map.putInt("satellites", amapLocation.getSatellites());
map.putDouble("altitude", amapLocation.getAltitude());
map.putDouble("speed", amapLocation.getSpeed());
map.putDouble("bearing", amapLocation.getBearing());
map.putString("address", amapLocation.getAddress());
map.putString("adCode", amapLocation.getAdCode());
map.putString("country", amapLocation.getCountry());
map.putString("province", amapLocation.getProvince());
map.putString("poiName", amapLocation.getPoiName());
map.putString("provider", amapLocation.getProvider());
map.putString("locationDetail", amapLocation.getLocationDetail());
map.putString("street", amapLocation.getStreet());
map.putString("streetNum", amapLocation.getStreetNum());
map.putString("city", amapLocation.getCity());
map.putString("cityCode", amapLocation.getCityCode());
map.putString("country", amapLocation.getCountry());
map.putString("district", amapLocation.getDistrict());
// map.putString("aoiName", amapLocation.getAOIName());
}
}
return map;
}