react-native - React Native map UrlTile

标签 react-native openstreetmap react-native-maps maptiler

我尝试在 UrlTile 中使用 openstreetmap 图 block ,但我得到了重复的图层、openstreetmap 和默认谷歌地图,如何删除谷歌地图图层?

enter image description here

这是我的组件:

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%",
  },
});

此外,当我用我自己的 MapTiler 服务器图 block 切换 openstreetmap 图 block 时,它不会显示任何内容,仅显示谷歌地图

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

最后一件事,我需要知道这是否会让我付出代价,我需要使用 Google API key 来运行 React-native-maps 库,我需要一些解释。

提前谢谢您。

最佳答案

将其添加到您的 MapView。

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

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

您可以在此页面上找到更多信息https://github.com/react-native-maps/react-native-maps#tile-overlay-using-local-tiles

关于react-native - React Native map UrlTile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71004690/

相关文章:

react-native - 如何隐藏 react-navigation 标题下的阴影?

android - 使用 osmdroid 时不显示 map

postgresql - 递归搜索拓扑网络表中的死胡同

android - 使用 animateToRegion() 与 animateCamera() 的优缺点

react-native - react 原生 FlatList scrollToItem 错误

javascript - 在React Native中找到数组元素的总和

react-native - React-Moment 给出 : "Invariant Violation: Text strings must be rendered within a <Text> component"

java - Osmdroid 定位 MarkerInfoWindow

javascript - React-native-map 标记颜色没有改变

android - 'com.google.android.gms :play-services-base' has different for the compile (15. 0.1) 和运行时 (16.0.1)