2

I am trying to use openstreetmap tile in UrlTile but I am getting duplicate layers, openstreetmap and default google map, how can I remove google map layer?

enter image description here

This is my component:

import { StyleSheet, Text, View, Button } from "react-native";
import MapView, {
  PROVIDER_GOOGLE,
  MAP_TYPES,
  PROVIDER_DEFAULT,
  UrlTile,
  Marker,
} from "react-native-maps";
import React, { useEffect } from "react";

export default function Home({ navigation }) {
  let location = {
    latitude: 23.259933,
    longitude: 77.412613,
    latitudeDelta: 0.009,
    longitudeDelta: 0.009,
  };

  return (
    <View style={styles.container}>
      <View style={styles.myMap}>
        <MapView
          region={location}
          rotateEnabled={false}
          style={{ flex: 1 }}
          style={styles.map}
          showsUserLocation
        >
          <UrlTile
            urlTemplate="https://a.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png"
            maximumZ={19}
          />
          <Marker
            title="Home"
            coordinate={{
              latitude: location.latitude,
              longitude: location.longitude,
            }}
          />
        </MapView>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#ffd",
    alignItems: "center",
    justifyContent: "center",
  },
  btn1: {
    margin: 20,
  },
  btn2: {
    margin: 20,
  },
  btns: {
    flex: 1,
    flexDirection: "row",
    backgroundColor: "grey",
  },
  myMap: {
    flex: 2,
    backgroundColor: "white",
    width: "100%",
    marginTop: 30,
    marginBottom: 30,
  },
  map: {
    width: "100%",
    height: "100%",
  },
});

Also, when I switch openstreetmap tile with my own MapTiler server tiles it doesn't show anything, just google map

'http://localhost:3650/api/maps/satellite-hybrid/{z}/{x}/{y}.png'

One last thing, I need to know if this going to cost me, I am required to use Google API key to run react-native-maps library, I need some explanation.

Thank you in advance.

Bassel Turky
  • 371
  • 7
  • 15

2 Answers2

1

Add this to your MapView.

mapType={Platform.OS == "android" ? "none" : "standard"}

or

mapType={Platform.OS == "ios" ? "none" : "standard"}

You can find more info on this page https://github.com/react-native-maps/react-native-maps#tile-overlay-using-local-tiles

sadiq ali
  • 67
  • 1
  • 8
0

have you tried to consult the MapTiler Documentation yet? There might be some tips to help you: https://docs.maptiler.com/maplibre-gl-native-android/?_ga=2.172534305.364226297.1644212649-2087445124.1628005081&_gl=1*1hky133*_ga*MjA4NzQ0NTEyNC4xNjI4MDA1MDgx*_ga_K4SXYBF4HT*MTY0NDI0NDA5My4yLjEuMTY0NDI0NTAxMC41Ng..

May I ask if the Google Map is essential? Since you use MapTiler Server, it could be also replaced with a MapTiler Data Layer.

If you are interested in getting to know more, feel free to contact us at support@maptiler.com

MapTiler
  • 1,754
  • 14
  • 22