【问题标题】:Update Marker position with Animation in Android Studio在 Android Studio 中使用动画更新标记位置
【发布时间】:2023-04-07 20:19:01
【问题描述】:

我已成功从数据库中存储的一些数据中获取纬度和经度。但我无法更新地图上的标记位置。请有人帮助我提供代码或如何做到这一点。

【问题讨论】:

    标签: android android-studio google-maps-markers android-maps-v2


    【解决方案1】:

    使用CameraUpdate 试试这个,

    LatLng coordinate = new LatLng(lat, lng); //Store these lat lng values somewhere. These should be constant.
    CameraUpdate location = CameraUpdateFactory.newLatLngZoom(coordinate, 15);
    mMap.animateCamera(location);
    

    或者也可以用这个,

         LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());  
         MarkerOptions markerOptions = new MarkerOptions(); 
         markerOptions.position(latLng); 
         markerOptions.title(totalAddress); //Here Total Address is address which you want to show on marker
         mMap.clear();
    
    
         markerOptions.icon(
         BitmapDescriptorFactory
        .defaultMarker(BitmapDescriptorFactory.HUE_AZURE)); 
    
         markerOptions.getPosition(); 
         mCurrLocationMarker = mMap.addMarker(markerOptions); 
         mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
         mMap.animateCamera(CameraUpdateFactory.zoomTo(11)); 
    

    【讨论】:

    • 是 getPosition() 方法来获取我正在测试地图的设备位置吗??
    • 不,其实我觉得你已经有了你在帖子中提到的纬度和经度。这个markerOptions.getPosition() 将返回我们使用markerOptions.position(latLng) 在它上面设置的那个。那不是设备的当前位置。
    猜你喜欢
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    相关资源
    最近更新 更多