I'm trying to put a tag on the map and it's giving an error of NullPointExeption
The method follows:
private void setMapaGoogle() {
if (mapa != null) {
mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
try{
LatLng latlng = new LatLng(latitude,longitude);
**mapa = SupportMapFragment.newInstance(new GoogleMapOptions().zOrderOnTop(true)).getMap();**
mapa.addMarker(new MarkerOptions()
.position(latlng)
.title("Onde Estou!")
.snippet("")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mark_mapa_local_atual))
.visible(true));
// Move a camera para a posição.
mapa.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),14));
//Efeito na camera do mapa
mapa.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
mapa.getUiSettings().setZoomControlsEnabled(false);
mapa.getUiSettings().setCompassEnabled(false);
mapa.getUiSettings().setMyLocationButtonEnabled(false);
} catch (Exception e) {
StringBuilder sb = new StringBuilder().append(e.getClass().getSimpleName());
if (e.getMessage() != null) {
sb.append("\n");
sb.append(e.getMessage());
}
Log.e("Exeção", sb.toString());
aux = sb.toString();
// this code write out all message
Log.e("Exeção","setMapaGoogle", e);
}
}else{
setMapaGoogle();
}
}
The error occurs on the line:
mapa = SupportMapFragment.newInstance(new GoogleMapOptions().zOrderOnTop(true)).getMap();