javascript - 如何在 React Native 中集成 Open Street map ?

标签 javascript reactjs react-native google-maps openstreetmap

我想使用 Open Street Map 而不是 Google map , 所以我用react-native-maps-osmdroid处理它

但是我在 View 中看不到任何 map ,所以我应该在设置时添加一些东西吗?

"I don't have Google key cuz react-native-maps require it so that's reason to use react-native-maps-osmdroid"

截图

screenshot

代码

import React, {Component} from 'react';
import {Text, View} from 'react-native';
import MapView, {Marker} from 'react-native-maps-osmdroid';

class MapTest extends Component {
  render() {
    return (
      <View>
        <MapView
          style={{flex: 1}}
          initialRegion={{
            latitude: 37.78825,
            longitude: -122.4324,
            latitudeDelta: 0.0922,
            longitudeDelta: 0.0421,
          }}>
          <Marker
            title="Home"
            color="#f00"
            coordinate={{
              latitude: 37.78825,
              longitude: -122.4324,
              latitudeDelta: 0.0922,
              longitudeDelta: 0.0421,
            }}
          />
        </MapView>
      </View>
    );
  }
}

export default MapTest;

最佳答案

您仍然需要使用 react-native-maps-osmdroid 的 API key .

The actual map implementation depends on the platform. On Android, one has to use >Google Maps, which in turn requires you to obtain an API key for the Android SDK.

您可以免费获得 API key 。关注this tutorial即可

关于javascript - 如何在 React Native 中集成 Open Street map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59504789/

相关文章:

javascript - WebSocket 连接到 '...' 失败 : Invalid frame header

javascript - 如何固定jquery lightbox的宽度和高度?

javascript - 使用 React Router Dom 的服务器端呈现出现错误 : Warning: React. createElement:类型无效——需要一个字符串

javascript - React 状态下错误 "Cannot read property ' fname' of undefined"

javascript - react native : Text and Icon inline

react-native - React Native 中未生成短动态链接

javascript - 从闭包中取回数据

javascript - ExtJS 5 : Parent model convert dependency on Child association

javascript - 如何在reactjs中获取元素属性

react-native - React Native 重新安装屏幕