Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我怎样才能只用一个手指在谷歌地图API(android)上旋转?_Android_Google Maps_Location - Fatal编程技术网

我怎样才能只用一个手指在谷歌地图API(android)上旋转?

我怎样才能只用一个手指在谷歌地图API(android)上旋转?,android,google-maps,location,Android,Google Maps,Location,我正在开发一个可以锁定用户位置的应用程序,就像新的口袋妖怪go应用程序一样,我需要找到一种只用一个手指旋转的方法。我想可能会有一些“拖动”功能,但我还没有找到任何可以工作的。有什么想法吗?我也有同样的问题。我所做的是添加了一个自定义视图,该视图扩展了地图顶部的FrameLayout,并向其添加了一个“onTouchEvent”方法。 我计算了两条线之间的角度- 第一条线位于屏幕上的第一个接触点和地图中心之间。 第二个是手指最后接触的位置和地图中心之间。剩下要做的最后一件事是更新地图对象的方位,并

我正在开发一个可以锁定用户位置的应用程序,就像新的口袋妖怪go应用程序一样,我需要找到一种只用一个手指旋转的方法。我想可能会有一些“拖动”功能,但我还没有找到任何可以工作的。有什么想法吗?

我也有同样的问题。我所做的是添加了一个自定义视图,该视图扩展了地图顶部的FrameLayout,并向其添加了一个“onTouchEvent”方法。 我计算了两条线之间的角度- 第一条线位于屏幕上的第一个接触点和地图中心之间。 第二个是手指最后接触的位置和地图中心之间。剩下要做的最后一件事是更新地图对象的方位,并将值first touch变量指定给手指在屏幕上最后移动的位置

class touch view extends FrameLayout {

...

public boolean onTouchEvent(MotionEvent eve) {
    Point touchPoint = new Point();  //first point on screen the user's finger touches
    final GoogleMap map;
    final int action = MotionEventCompat.getActionMasked(eve);
    int pointerIndex = MotionEventCompat.getActionIndex(eve);
    GestureDetector g = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener());
    g.onTouchEvent(eve);
    switch (action){
        case MotionEvent.ACTION_DOWN:
            // get the point the user's finger touches
            touchPoint.x =(int) MotionEventCompat.getX(eve,pointerIndex);
            touchPoint.y =(int) MotionEventCompat.getY(eve,pointerIndex);
            break;
        case MotionEvent.ACTION_MOVE:
            if(eve.getPointerCount()<2) {   // leave two finger gestures for other actions
                final Point newTouchPoint = new Point();  // the new position of user's finger on screen after movement is detected
                newTouchPoint.x = (int) MotionEventCompat.getX(eve, pointerIndex);
                newTouchPoint.y = (int) MotionEventCompat.getY(eve, pointerIndex);
                Point centerOfMap = getCenterOfMapAsPoint();   // center of map(as Point object) for calculation of angle
                // now you need to calculate the angle betwwen 2 lines with centerOfMap as center:
                //line 1: imaginary line between first touch detection on screen - and the center of the map
                //line 2: imaginary line between last place finger moved on screen - and the center of the map
                final float angle = angleBetweenLines(centerOfMap, touchPoint, centerOfMap, newTouchPoint);
                final LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());  //set camera movement to that position
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        // move the camera (NOT animateCamera() ) to new position with "bearing" updated
                        map.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder().target(latlng).tilt(67.5f).zoom(map.getCameraPosition().zoom).bearing(map.getCameraPosition().bearing - angle).build()));
                    }
                });
                touchPoint = newTouchPoint; // update touchPoint value
                return true;
            }else{
                break;
            }
    }
    return true;
}

// convert center of map from Latln object to Point object
public Point getCurrentLocation(){
    Projection projection = map.getProjection();
    return projection.toScreenLocation(new LatLng(location.getLatitude(), location.getLongitude()));
}

我也有同样的问题。我所做的是添加了一个自定义视图,该视图扩展了地图顶部的FrameLayout,并向其添加了一个“onTouchEvent”方法。 我计算了两条线之间的角度- 第一条线位于屏幕上的第一个接触点和地图中心之间。 第二个是手指最后接触的位置和地图中心之间。剩下要做的最后一件事是更新地图对象的方位,并将值first touch变量指定给手指在屏幕上最后移动的位置

class touch view extends FrameLayout {

...

public boolean onTouchEvent(MotionEvent eve) {
    Point touchPoint = new Point();  //first point on screen the user's finger touches
    final GoogleMap map;
    final int action = MotionEventCompat.getActionMasked(eve);
    int pointerIndex = MotionEventCompat.getActionIndex(eve);
    GestureDetector g = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener());
    g.onTouchEvent(eve);
    switch (action){
        case MotionEvent.ACTION_DOWN:
            // get the point the user's finger touches
            touchPoint.x =(int) MotionEventCompat.getX(eve,pointerIndex);
            touchPoint.y =(int) MotionEventCompat.getY(eve,pointerIndex);
            break;
        case MotionEvent.ACTION_MOVE:
            if(eve.getPointerCount()<2) {   // leave two finger gestures for other actions
                final Point newTouchPoint = new Point();  // the new position of user's finger on screen after movement is detected
                newTouchPoint.x = (int) MotionEventCompat.getX(eve, pointerIndex);
                newTouchPoint.y = (int) MotionEventCompat.getY(eve, pointerIndex);
                Point centerOfMap = getCenterOfMapAsPoint();   // center of map(as Point object) for calculation of angle
                // now you need to calculate the angle betwwen 2 lines with centerOfMap as center:
                //line 1: imaginary line between first touch detection on screen - and the center of the map
                //line 2: imaginary line between last place finger moved on screen - and the center of the map
                final float angle = angleBetweenLines(centerOfMap, touchPoint, centerOfMap, newTouchPoint);
                final LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());  //set camera movement to that position
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        // move the camera (NOT animateCamera() ) to new position with "bearing" updated
                        map.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.builder().target(latlng).tilt(67.5f).zoom(map.getCameraPosition().zoom).bearing(map.getCameraPosition().bearing - angle).build()));
                    }
                });
                touchPoint = newTouchPoint; // update touchPoint value
                return true;
            }else{
                break;
            }
    }
    return true;
}

// convert center of map from Latln object to Point object
public Point getCurrentLocation(){
    Projection projection = map.getProjection();
    return projection.toScreenLocation(new LatLng(location.getLatitude(), location.getLongitude()));
}

还不能发表评论,但我发现Semikunchezz解决方案不便于使用。我们可以扩展SupportMapFragment,而不是单独的FrameLayout,如Gaucho所示:
还不能发表评论,但我发现Semikunchezz解决方案不便于使用。我们可以扩展SupportMapFragment,而不是单独的FrameLayout,如Gaucho所示:

考虑到人们对UI的期望是这样的:您可能想解释一下您的想法。除非它只是一个+/-按钮,但用于旋转。你的意思是在应用程序中解释还是在这里解释?用一个手指像纸一样拖动地图是一种常见的手势。正如您在“材质UI模式”链接中看到的那样,旋转使用两个手指。您可能想为您的应用程序解释“仅用一个手指旋转”的含义,以及它与圆形模式中的拖动有何区别。鉴于这是人们期望UI的行为方式:您可能想解释您的想法。除非它只是一个+/-按钮,但用于旋转。你的意思是在应用程序中解释还是在这里解释?用一个手指像纸一样拖动地图是一种常见的手势。正如您在“材质UI模式”链接中看到的那样,旋转使用两个手指。你可能想为你的应用解释一下“只用一个手指旋转”是什么意思,以及它与圆形模式的拖动有什么不同。