|
楼主 |
发表于 2017-6-19 15:35:04
|
显示全部楼层
BaiduLocation内部类
public class MyLocationListener implements BDLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null)
return;
try {
JSONObject coords = new JSONObject();
coords.put("latitude", location.getLatitude());
coords.put("longitude", location.getLongitude());
coords.put("radius", location.getRadius());
jsonObj.put("coords", coords);
int locationType = location.getLocType();
jsonObj.put("coorType", "bd09ll");
jsonObj.put("code", locationType);
jsonObj.put("message", getErrorMessage(locationType));
switch (location.getLocType()) {
case BDLocation.TypeGpsLocation:
coords.put("speed", location.getSpeed());
coords.put("altitude", location.getAltitude());
jsonObj.put("SatelliteNumber", location.getSatelliteNumber());
break;
case BDLocation.TypeNetWorkLocation:
jsonObj.put("address", location.getAddrStr());
break;
}
//根据上边option设置的时间循环返回坐标点
results = new PluginResult(PluginResult.Status.OK, jsonObj);
results.setKeepCallback(true);
callbackContext.sendPluginResult(results);
Log.d("BaiduLocationPlugin", "run: " + jsonObj.toString());
result = true;
} catch (JSONException e) {
callbackContext.error(e.getMessage());
result = true;
}
} |
|