代码拉取完成,页面将自动刷新
定位图标箭头指向手机朝向示例
###1:配置搭建AndroidSDK工程###
@Override
public void onSensorChanged(SensorEvent event) {
if (System.currentTimeMillis() - lastTime < TIME_SENSOR) {
return;
}
switch (event.sensor.getType()) {
case Sensor.TYPE_ORIENTATION: {
float x = event.values[0];
x += getScreenRotationOnPhone(mContext);
x %= 360.0F;
if (x > 180.0F)
x -= 360.0F;
else if (x < -180.0F)
x += 360.0F;
if (Math.abs(mAngle - x) < 3.0f) {
break;
}
mAngle = Float.isNaN(x) ? 0 : x;
if (mMarker != null) {
mMarker.setRotateAngle(360 - mAngle);
}
lastTime = System.currentTimeMillis();
}
}
}
/**
* 获取当前屏幕旋转角度
*
* @param context
* @return 0表示是竖屏; 90表示是左横屏; 180表示是反向竖屏; 270表示是右横屏
*/
public static int getScreenRotationOnPhone(Context context) {
final Display display = ((WindowManager) context
.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
switch (display.getRotation()) {
case Surface.ROTATION_0:
return 0;
case Surface.ROTATION_90:
return 90;
case Surface.ROTATION_180:
return 180;
case Surface.ROTATION_270:
return -90;
}
return 0;
}
if (!mFirstFix) {
mFirstFix = true;
addCircle(location, amapLocation.getAccuracy());//添加定位精度圆
addMarker(location);//添加定位图标
mSensorHelper.setCurrentMarker(mLocMarker);//定位图标旋转
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location,18));
} else {
mCircle.setCenter(location);
mCircle.setRadius(amapLocation.getAccuracy());
mLocMarker.setPosition(location);
aMap.moveCamera(CameraUpdateFactory.changeLatLng(location));
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。