2016-09-23 6 views
0

map with default marker that is never setКарта показывает по умолчанию маркера, но он никогда не устанавливается

В центре карт есть маркер, который всегда отображается на этом месте, когда я начала свою деятельность с фрагментом карты в нем. Но я никогда не устанавливал этот маркер ... Кто-нибудь знает, почему это так, и возможно, как я могу удалить этот маркер?

Вот мой код:

@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 

    int permissionCheck = ContextCompat.checkSelfPermission(MapsActivity.this, 
      android.Manifest.permission.ACCESS_FINE_LOCATION); 

    if(permissionCheck == PackageManager.PERMISSION_GRANTED){ 
     getCurrentLocation(); 
     onSearch(); 
    }else if(permissionCheck == PackageManager.PERMISSION_DENIED){ 
     onSearch(); 
    } 
} 
//gets current location of the user. 
public void getCurrentLocation() { 
    double lat = 0; 
    double lng = 0; 
    try { 
     mMap.setMyLocationEnabled(true); //allows query of current location. 
    }catch(SecurityException e){ 
     e.printStackTrace(); 
    } 

    LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    Geocoder geocoderGetAddress = new Geocoder(MapsActivity.this); 
    try{ 
     Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
     if(location!=null) { 
      lat = location.getLatitude(); 
      lng = location.getLongitude(); 
     } 
    }catch(SecurityException e){ 
     e.printStackTrace(); 
    } 
    //the rest of this method gets the address from the geocoder, so that it can be displayed as a String on the marker info window. 
    String displayAddress =""; 
    try { 
     List<Address> currAddress = geocoderGetAddress.getFromLocation(lat, lng, 1); 
     if(currAddress.size() >0){ 
      for(int i=0; i<currAddress.get(0).getMaxAddressLineIndex();i++){ 
       displayAddress += currAddress.get(0).getAddressLine(i) +"\n"; 
      } 
     } 
    }catch (IOException e){ 
     e.printStackTrace(); 
    } 
    mMap.addMarker(new MarkerOptions().position(new LatLng(lat,lng)).title(myLoc).snippet(displayAddress)); 
    LatLng myLatLng = new LatLng(lat, lng); 
    mMap.animateCamera(CameraUpdateFactory.newLatLng(myLatLng)); 
    initAcceptButton(); 
} 

Спасибо!

+0

Вы добавляете его 'mMap.addMarker' и анимировать его в центр с' mMap.animateCamera' – zgc7009

+0

Нет, я только добавить этот маркер, когда я получаю текущее местоположение смартфона. –

+0

Это не меняет того факта, что именно это вы добавляете, ваш текущий lat/lng еще не исправлен. – zgc7009

ответ

0

Я просто решил проблему с добавлением

if(lat!= 0 || lng != 0){ 
//add marker here 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^