openmobilehub / react-native-omh-maps

https://openmobilehub.github.io/react-native-omh-maps/
Apache License 2.0
22 stars 0 forks source link

Map View is not loading sometimes on android #109

Open draggie opened 1 week ago

draggie commented 1 week ago

On Android, when I add my own markers, the map often doesn’t load—I’m not sure what’s going on. Occasionally, this message appears: Attempt to invoke virtual method 'org.osmdroid.views.MapViewRepository org.osmdroid.views.MapView.getRepository() on a null object reference.’ In my case, the app is different in that it renders these markers dynamically from a collection after it’s loaded—what’s strange is that it works sometimes, in most cases there is no error even - just empty screen.

export const WeatherMap = () => {
  const cities = useCities();
  const forecast = useLoadForecast(cities.data);
  const markers = useMemo(
    () =>
      forecast.data?.list.map(item => (
        <OmhMarker
          key={item.id}
          icon={{
            uri: `https://openweathermap.org/img/w/${item.weather[0].icon}.png`,
            width: 150,
            height: 150,
          }}
          title={`${item.name}: ${item.main.temp}C`}
          position={{
            latitude: item.coord.lat,
            longitude: item.coord.lon,
          }}
        />
      )),
    [forecast],
  );

  return (
    <View style={style.container}>
      <OmhMapView>{markers}</OmhMapView>
    </View>
  );
};