【问题标题】:How to Move google Map along with periodically moving marker如何移动谷歌地图以及定期移动的标记
【发布时间】:2016-08-30 14:05:26
【问题描述】:

我正在开发一个谷歌地图应用程序,我在其中设置了谷歌地图和移动车辆的标记。我从 API 获取纬度和经度,并定期(每 25 秒)更新谷歌地图上的标记。

         When updating marker I am unable to move the google map along with the marker. How to move the google map along with the periodically moving marker.

任何帮助都应该对我有很大的帮助。

【问题讨论】:

    标签: android google-maps android-layout google-maps-markers marker


    【解决方案1】:

    因此,为了随着标记位置的变化移动地图,您可以执行以下操作:

    public void onLocationChanged(Location loc) {
        //some marker movements here...
    
        CameraPosition currentPlace = new CameraPosition.Builder()
                .target(new LatLng(loc.getLatitude(), loc.getLongitude())
                .tilt(0f)
                .zoom(18)
                .build();
    
        map.animateCamera(CameraUpdateFactory.newCameraPosition(currentPlace), 200, null);
    }
    

    当然你需要访问GoogleMap对象。

    【讨论】:

    • 感谢 Rybzor 提供此代码 sn-p。这很有帮助。
    【解决方案2】:

    以下代码sn-ps说明了一些常见的移动摄像头的方式:

    private static final LatLng SYDNEY = new LatLng(-33.88,151.21);
    private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1);
    
    private GoogleMap map;
    ... 
    
    // Obtain the map from a MapFragment or MapView.
    
    // Move the camera instantly to Sydney with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15));
    
    // Zoom in, animating the camera.
    map.animateCamera(CameraUpdateFactory.zoomIn());
    
    // Zoom out to zoom level 10, animating with a duration of 2 seconds.
    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    
    // Construct a CameraPosition focusing on Mountain View and animate the camera to that position.
    CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(MOUNTAIN_VIEW)      // Sets the center of the map to Mountain View
                    .zoom(17)                   // Sets the zoom
                    .bearing(90)                // Sets the orientation of the camera to east
                    .tilt(30)                   // Sets the tilt of the camera to 30 degrees
                    .build();                   // Creates a CameraPosition from the builder
    
    map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    

    基于Documentation for the Android Google Maps API

    编辑:

    我在 Udacity 上发现了一些关于 Google 地图的有趣课程:

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 2013-04-08
      • 2020-05-07
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多