react-native-baidu-map

摘要:
1.创建新的RN项目:(BaiDuMapTest)出现以下界面,表示新项目成功。2.安装act native baidu map(注意:确保安装在项目根目录下):输入:npminstallact native baidu map--save3.Xcode配置:BuildPhases-˃LinkBinaryWithLibrarys Add libRCTBaiduMap.aBuild

1.新建一个RN项目:(BaiDuMapTest)


react-native-baidu-map第1张

出现以下界面,就表示新建项目成功了

react-native-baidu-map第2张

2.安装react-native-baidu-map(注意:一定要在项目根目录下进行安装):


在终端输入:
npm install react-native-baidu-map --save

react-native-baidu-map第3张

3.Xcode配置:


react-native-baidu-map第4张
react-native-baidu-map第5张

Build Phases->Link Binary With Libraries 加入 libRCTBaiduMap.a

react-native-baidu-map第6张

Build Settings->Search Paths, Framework search paths 添加$(PROJECT_DIR)/../node_modules/react-native-baidu-map/ios/lib,Header search paths 添加 $(SRCROOT)/../node_modules/react-native-baidu-map/ios/RCTBaiduMap

react-native-baidu-map第7张
图片.png
react-native-baidu-map第8张
图片.png

添加依赖, react-native-baidu-map/ios/lib 下的全部 framwordk:

react-native-baidu-map第9张
图片.png

方法:

react-native-baidu-map第10张
图片.png
react-native-baidu-map第11张
图片.png
react-native-baidu-map第12张
图片.png
react-native-baidu-map第13张
图片.png

然后继续添加:CoreLocation.framework和QuartzCore.framework、OpenGLES.framework、SystemConfiguration.framework、CoreGraphics.framework、Security.framework、libsqlite3.0.tbd(xcode7以前为 libsqlite3.0.dylib)、CoreTelephony.framework 、libstdc++.6.0.9.tbd(xcode7以前为libstdc++.6.0.9.dylib)
例如:

react-native-baidu-map第14张
图片.png

全部添加完后:

react-native-baidu-map第15张
图片.png

接下来添加 BaiduMapAPI_Map.framework/Resources/mapapi.bundle

react-native-baidu-map第16张
图片.png
react-native-baidu-map第17张
图片.png
react-native-baidu-map第18张
图片.png

4.AppDelegate.m init 初始化


#import "RCTBaiduMapViewManager.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    [RCTBaiduMapViewManager initSDK:@"api key"];//这里的api key 一定要在官网和APP的Bundle identifier对应,否则地图会显示失败
    ...
}
react-native-baidu-map第19张
图片.png

5.build一下,看看是否配置成功


此时可能会报这个错误:

react-native-baidu-map第20张
图片.png

解决办法:

#import "RCTViewManager.h"
#import "RCTConvert+CoreLocation.h"

改成

#import <React/RCTViewManager.h>
#import <React/RCTConvert+CoreLocation.h>

如图:

react-native-baidu-map第21张
图片.png

然后就build success啦~

6.到此为止,配置已经完成,我们可以在RN来玩一玩百度地图~


这里我们就参照官网的Demo给大家展示一下:

index.ios.js:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

import BaiduMapDemo from './BaiduMapDemo';

export default class BaiDuMapTest extends Component {
  render() {
    return (
      <BaiduMapDemo />
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('BaiDuMapTest', () => BaiDuMapTest);

BaiduMapDemo.js

/**
 * @author lovebing
 */

import React, {
  Component,
  PropTypes
} from 'react';

import {
  MapView,
  MapTypes,
  Geolocation
} from 'react-native-baidu-map';

import {
  Button,
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight
} from 'react-native';

import Dimensions from 'Dimensions';

export default class BaiduMapDemo extends Component {

  constructor() {
    super();

    this.state = {
      mayType: MapTypes.NORMAL,
      zoom: 15,
      center: {
        longitude: 113.981718,
        latitude: 22.542449
      },
      trafficEnabled: false,
      baiduHeatMapEnabled: false,
      markers: [{
        longitude: 113.981718,
        latitude: 22.542449,
        title: "Window of the world"
      },{
        longitude: 113.995516,
        latitude: 22.537642,
        title: ""
      }]
    };
  }

  componentDidMount() {
  }

  render() {
    return (
      <View style={styles.container}>
        <MapView 
          trafficEnabled={this.state.trafficEnabled}
          baiduHeatMapEnabled={this.state.baiduHeatMapEnabled}
          zoom={this.state.zoom}
          mapType={this.state.mapType}
          center={this.state.center}
          marker={this.state.marker}
          markers={this.state.markers}
          style={styles.map}
          onMarkerClick={(e) => {
            console.warn(JSON.stringify(e));
          }}
          onMapClick={(e) => {
          }}
        >
        </MapView>

        <View style={styles.row}>
          <Button title="Normal" onPress={() => {
            this.setState({
              mapType: MapTypes.NORMAL
            });
          }} />
          <Button style={styles.btn} title="Satellite" onPress={() => {
            this.setState({
              mapType: MapTypes.SATELLITE
            });
          }} /

免责声明:内容来源于网络,仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Qt获取uuid神经网络之dropout层下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

React Native之React Navigation踩坑

自动重装系统之后,已经很长一段时间没有来写React Native了,今天空闲之余,决定重新配置React Native的开发环境,继续踩坑... React Native的开发环境配置狠简单,只要依照网上给出的步骤,复制粘贴,在终端下操作就行。 React Native中文网开发环境配置 当一切都已完成之后,我怀着激动的心情,打开了Xcode,尝试运行一...

10种顶级javascript框架比较The Top 10 Javascript MVC Frameworks

转载于:http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/ Gordon L. Hempton是西雅图的一位黑客和设计师,他花费了几个月的时间研究和比较了12种流行的JavaScript MVC框架,并在博客中总结了每种框架的优缺点,最终的结果是,Ember...

redux入门学习

目录 Redux学习 1.用react脚手架创建一个新的项目 2.visual studio code安装simple react snippet 插件 3.然后再src目录下新建一个文件,TodoList.jsx 4.安装antd组件制作UI界面 5.使用antd制作UI界面 6.安装redux 7.创建redux中的仓库-store和reducer...

解决react下找不到原生高德地图AMap类的问题

方法1. 使用注释 //eslint-disable-next-line写在每个出现AMap类的前面一行,如下所示 原理是告诉eslint:注释下面这一行您别管。 方法2.http - https <scripttype="text/javascript"src="http://t.zoukankan.com/https://api.map.ba...

为什么react的组件要super(props)

  对这个问题纠结了好几天,一直没时间深入研究。在segmentfault看到有人提出了同样的问题,下面这篇SF给出了解释。为什么react的组件要super(props) 解释一:  调用super的原因:在ES6中,在子类的constructor中必须先调用super才能引用this super(props)的目的:在constructor中可以使用...

JSX设置CSS样式详解

JSX设置CSS样式详解 1. 使用className设置样式(CSS的其他选择器也是同理) (1)定义一个CSS文件style.css,和普通CSS一样定义class选择器 .sty1{//和普通CSS一样定义class选择器 background-color: red; color: white; font-size: 40px...