estoy empezando a programar en Android y estoy haciendo una app para mostrar una persona en el mapa. el tema es que por algún motivo a la hora de personalizar el infoWindows del marker muestra mal la información, no muestra la imagen y muestra el fondo transparente, también leí que se puede cambiar la ventana de los infoWindows pero en ningún lado pude encontrar información de como se hace.
acá les dejo el código para ver si pueden ayudarme. ya llevo todo el dia dándole vueltas y no hay caso. Desde ya mil gracias!
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleMap.InfoWindowAdapter{
private GoogleMap mMap;
private LocationManager locationManager;
private LocationListener locationListener;
private LatLng userLoc;
private Marker marker;
public void updateMap(Location location) {
marker.remove();
LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());
marker = mMap.addMarker(new MarkerOptions().position(userLocation).title("estas aca!"));
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateMap(lastKnownLocation);
}
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
this.userLoc = new LatLng(0,0);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.map_style));
this.marker =mMap.addMarker(new MarkerOptions().position(userLoc));
mMap.setInfoWindowAdapter(this);
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
userLoc = new LatLng(location.getLatitude(),location.getLongitude());
updateMap(location);
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
};
if (Build.VERSION.SDK_INT < 23) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
} else {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
} else {
mMap.setMyLocationEnabled(true);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastKnownLocation != null) {
this.userLoc = new LatLng(lastKnownLocation.getLatitude(),lastKnownLocation.getLongitude());
mMap.clear();
updateMap(lastKnownLocation);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLoc, 16));
}
}
}
}
@Override
public View getInfoWindow(Marker marker) {
/* View view = LayoutInflater.from(this).inflate(R.layout.info_window,null,false);
getLayoutInflater()*/
View view = getLayoutInflater().inflate(R.layout.info_window, null);
return view ;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
aca les dejo además el xml de la clase info_window:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/fotoImageViewInfoWindow"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="0"
android:contentDescription="@string/infowindow_fotos_context"
tools:srcCompat="@mipmap/map_icon_persona"
android:layout_gravity="center"/>
<TextView
android:id="@+id/razaTextViewInfoWindow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/gen_nombre"
android:textAlignment="center" />
<TextView
android:id="@+id/colorTextViewInfoWindow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/gen_colorpelo"
android:textAlignment="center" />
<TextView
android:id="@+id/fechaTextViewInfoWindow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/gen_fecha"
android:textAlignment="center" />
<TextView
android:id="@+id/horarioTextViewInfoWindow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/gen_horario"
android:textAlignment="center" />
<TextView
android:id="@+id/ubicacionTextViewInfoWindow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/gen_ubicacion"
android:textAlignment="center" />
<Button
android:id="@+id/button2"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="0"
android:background="@drawable/button_background_general"
android:text="@string/infowindow_button" />
</LinearLayout>