# react-native-baidu-map **Repository Path**: codefree/react-native-baidu-map ## Basic Information - **Project Name**: react-native-baidu-map - **Description**: No description available - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-08-07 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # react-native-ibuild-module-baidu-map ## Getting started `$ npm install react-native-ibuild-module-baidu-map --save` ### Mostly automatic installation `$ react-native link react-native-ibuild-module-baidu-map` ### Manual installation #### iOS 1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` 2. Go to `node_modules` ➜ `react-native-ibuild-module-baidu-map` and add `RNIbuildModuleBaiduMap.xcodeproj` 3. In XCode, in the project navigator, select your project. Add `libRNIbuildModuleBaiduMap.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` 4. Run your project (`Cmd+R`)< #### Android `Automatic installation works very well on android.If you are interesting in manual installation,the following statements are helpful.` 1. Open up `android/app/src/main/java/[...]/MainActivity.java` - Add `import com.reactlibrary.RNIbuildModuleBaiduMapPackage;` to the imports at the top of the file - Add `new IbuildMapPackage()` to the list returned by the `getPackages()` method 2. Append the following lines to `android/settings.gradle`: ``` include ':react-native-ibuild-module-baidu-map' project(':react-native-ibuild-module-baidu-map').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-ibuild-module-baidu-map/android') ``` 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: ``` compile project(':react-native-ibuild-module-baidu-map') ``` 4. Open up `android/app/src/main/AndroidManifest.xml`,insert baidumap apikey configuration ```xml ``` ## Usage ###地图 ```javascript import BDMapView from 'react-native-ibuild-module-baidu-map'; render(){ return ... } mapUpdateStatus={} nativeEventCallback={}> ... } ``` ### nativeEventCallback nativeEventCallback has a callback parameter `event` which gives out a nativeEvent : ```javascript nativeEventCallback(event){ let nativeEvent = event.nativeEvent; //nativeEvent has two field:type and params //type is the name of nativeEvent //params is the data callback if (nativeEvent.type === "onDataSelect") { //yourFunc(nativeEvent.params); } } ``` #### nativeEvent.type defines ##### onDataSelect ```javascript //nativeEvent.params //province: { provinceID: 2, provinceName: '河北省', latitude: 38.04774, longitude: 114.511258, totalProjectCount: 80, } //city: { provinceID: 1, provinceName: '四川省', cityID: 103, cityName: '攀枝花市', latitude: 26.586558, longitude: 101.722387, totalProjectCount: 31, } //project: { provinceID: 1, provinceName: '四川省', cityID: 100, cityName: '成都市', latitude: 30.663523, longitude: 104.072233, totalProjectCount: 0, projectID: 10000, projectName: '天府广场1期项目', projectImage: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4097442918,2012818175&fm=117&gp=0.jpg' } ``` ###定位 ```javascript import {IbuildLocation} from 'react-native-ibuild-module-baidu-map' let resp = await IbuildLocation.getCurrentPosition() /*resp format { 
address
: 
"中国四川省成都市武侯区天府二街", 
altitude
: 
5
e-324
, buildingId
: 
null, 
buildingName
: 
null, 
city
: 
"成都市"
, cityCode
: 
"75"
, country
: 
"中国", 
countryCode
: 
"0", 
direction
: 
-1, 
district
: 
"武侯区", latitude
: 
30.557588
, longitude
: 
104.065788
, province
: 
"四川省"
, radius
: 
40.48240280151367
, street: "天府二街"
, streetNumber: ""
 } */ ```