Usage
您可以从expo导入MapView,因为react-native-maps包含在expo中。 (如果您使用 expo 并且没有弹出您的应用程序,则没有任何集成或链接步骤。我想文档对此不是很清楚......)
只需从博览会导入,如下所示:
import { MapView } from 'expo'
并比照常使用它并在反应本机地图的文档 https://github.com/react-native-community/react-native-maps:
<MapView
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
集成 Api 密钥
如果您使用 expo,来自 google play 控制台的 api 密钥属于 app.json 的 android 和 ios 部分。
将其添加到您的 app.json > android.config 中:
"googleMaps": { "apiKey": "<android maps api key>" }
并将其添加到您的 app.json > ios.config 中:
"googleMapsApiKey": "<ios maps api key>"
你的 app.json 最后应该包含这样的内容(以及通常在那里的所有其他内容):
{
"expo": {
"android": {
"package": "com.company",
"config": {
"googleMaps": {
"apiKey": "<android maps key>"
}
}
},
"ios": {
"bundleIdentifier": "com.company",
"config": {
"googleMapsApiKey": "<ios maps api key>"
}
}
}
}