每分钟的标记都是平滑移动的,但不会删除android地图上的旧标记

每分钟的标记都是平滑移动的,但不会删除android地图上的旧标记,android,google-maps,google-maps-markers,Android,Google Maps,Google Maps Markers,我每分钟都从地图上显示的共享首选项中获得 Marker每分钟都在完美移动,但不会移除旧的Marker(它每分钟都会显示新的Marker) 但是关闭和打开地图片段可以完美地显示单个标记 请帮助我如何修复此问题。我还尝试了标记。删除 我在OnLocation-Changed方法中调用了下面的方法 /* 方法在UI上显示位置 */ private void displayLocation() { 尝试 { mLastLocation=LocationServices.FusedLocationApi.

我每分钟都从地图上显示的共享首选项中获得

  • Marker每分钟都在完美移动,但不会移除旧的Marker(它每分钟都会显示新的Marker)

  • 但是关闭和打开地图片段可以完美地显示单个标记
  • 请帮助我如何修复此问题。我还尝试了标记。删除

  • 我在OnLocation-Changed方法中调用了下面的方法

    /* 方法在UI上显示位置 */

    private void displayLocation()
    {
    尝试
    {
    mLastLocation=LocationServices.FusedLocationApi.getLastLocation(mgoogleapClient);
    如果(mLastLocation!=null)
    {
    双纬度=mLastLocation.getLatitude();
    double longitude=mLastLocation.getLongitude();
    //从会话获取用户数据
    HashMap user=session.getGPSPING();
    //UserLat
    字符串LatLongUser=“”;
    LatLongUser=user.get(sessionmanager for_Register.KEY_LATLONG);
    如果(!LatLongUser.equals(“”)
    {
    Log.i(“LatLong地图上的PING”,LatLongUser);
    字符串[]LanlongArr=LatLongUser.split(“/”);
    List Lanlonglist1=Arrays.asList(LanlongArr);
    int length=Lanlonglist1.size();
    arraylist\u DetailLineWalker=新建arraylist试试这个

      Marker now;
      @Override
      public void onLocationChanged(Location location) {
    
      if(now != null){
            now.remove();   //if the marker is already added then remove it
        }
    
       // Getting latitude of the current location
       double latitude = location.getLatitude();
    
       // Getting longitude of the current location
        double longitude = location.getLongitude();
    
      // Creating a LatLng object for the current location
        LatLng latLng = new LatLng(latitude, longitude);
        now = googleMap.addMarker(new MarkerOptions().position(latLng)));
     }
    
    如需参考,请访问此


    我已经在问号中提到了。删除无效?您添加了两次标记,但只删除了一次时间标记marker1=googleMap.addMarker(markerOptionsLineWalker);/*添加了第一次标记*/if(marker1!=null){marker1.remove();}//将标记添加到地图Google map.addMarker(markerOptionsLineWalker);/*第二次添加标记*/@Kumar你明白了吗?它将删除For循环中的所有标记。我不想删除所有标记。我只想删除重复的标记。
      Marker now;
      @Override
      public void onLocationChanged(Location location) {
    
      if(now != null){
            now.remove();   //if the marker is already added then remove it
        }
    
       // Getting latitude of the current location
       double latitude = location.getLatitude();
    
       // Getting longitude of the current location
        double longitude = location.getLongitude();
    
      // Creating a LatLng object for the current location
        LatLng latLng = new LatLng(latitude, longitude);
        now = googleMap.addMarker(new MarkerOptions().position(latLng)));
     }