文档:https://github.com/react-native-maps/react-native-maps#using-a-custom-tile-overlay
我想将 react-native-maps 与 自定义图块 一起使用,并且我不想使用 Google 提供商。
使用以下命令安装后:
npm install react-native-maps --save
当我运行项目时,出现以下错误:
API Key not found. Check that <meat-data android:name="com.google.android.geo.API_KEY" andorid:value="your API Key" /> is in the <application> element of AndroidManifest.xml
这是 React Native 中的组件:
import React from 'react';
import { Dimensions, StyleSheet, View } from 'react-native';
import MapView, { Marker } from 'react-native-maps';
const App = () => {
return (
<View style={{ flex: 1 }}>
<MapView
style={{ ...StyleSheet.absoluteFillObject, }}
provider={undefined}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
<UrlTile
urlTemplate="http://c.tile.openstreetmap.org/{z}/{x}/{y}.png"
zIndex={1}
/>
<Marker coordinate={{
latitude: 37.78825,
longitude: -122.4324,
}} pinColor="red" />
</MapView>
</View>
)
}
阅读此处的文档 - 地图文档
您需要注册并设置计费帐户并获取 API 密钥才能开始使用地图。