我正在嘗試構建一個android應用程序,以在android工作室中的android地圖API v2上滾動。我想用手機的加速度傳感器在各個方向上滾動地圖。例如,如果手機向右傾斜45度,我希望地圖有爭議地向右移動45度。從我已經發現的,我只能通過latlong目標或像素移動照相機(滾動),有沒有辦法使用X,Y座標的角度來做到這一點? 這些是我試過的樣品: 1-用拉特朗目標移動相機。從X,Y採用加速度實用滾動android地圖
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View
.zoom(20) // Sets the zoom
.bearing(20) // Sets the orientation of the camera to east
.tilt(10) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 1000, null);
2 - 查找手機角度:
float X = (float)Math.round(event.values[0]);
float Y= (float)Math.round(event.values[1]);
float angle = (float) (Math.atan2(X, Y)/(Math.PI/180));
我希望任何新的想法的角度來做到這一點還是有辦法moveCamera。
什麼「有爭議的向右移動45度」是什麼意思?你的意思是每秒45度?如何將手機的傾斜振幅(度)轉換爲移動相機的速度? –
@MehmetKologlu當我改變手機的角度時,我可以使用onSensorChanged方法以與手機相同的方向爭用相機。我最大的問題是,當我想使用moveCamera的animateCamera時,我仍然需要放下下一個目標點,而在我的情況下,沒有具體的目標。 – Hussein
使用animateCamera並將攝像機設置爲離當前視圖中心偏離的點(度數爲常數)。做這個動畫時,像'deviceTilted == true' –