Skip to content

Commit

Permalink
实现 iOS 定位模块
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuxiang committed Apr 25, 2018
1 parent 7b2c16e commit d5b2af4
Show file tree
Hide file tree
Showing 18 changed files with 1,687 additions and 16 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
.gradle/
node_modules/
build/
xcuserdata/
*.xcworkspace/
Pods/

*.iml
local.properties
local.properties
Podfile.lock
23 changes: 15 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const style = StyleSheet.create({
controls: {
flexDirection: "row",
justifyContent: "space-around",
marginTop: 12,
marginBottom: 24
},
item: {
Expand All @@ -27,9 +28,13 @@ class App extends React.Component {
state = { location: {} }

async componentDidMount() {
await Geolocation.init("043b24fe18785f33c491705ffe5b6935")
await Geolocation.init({
ios: "9bd6c82e77583020a73ef1af59d0c759",
android: "043b24fe18785f33c491705ffe5b6935"
})
Geolocation.setOptions({
interval: 10000
interval: 10000,
distanceFilter: 10,
})
Geolocation.addLocationListener(location =>
this.updateLocationState(location)
Expand All @@ -41,14 +46,16 @@ class App extends React.Component {
}

updateLocationState(location) {
location.timestamp = new Date(location.timestamp).toLocaleString()
this.setState({ location })
console.log(location)
if (location) {
location.timestamp = new Date(location.timestamp).toLocaleString()
this.setState({ location })
console.log(location)
}
}

startLocation = () => Geolocation.start()
stopLocation = () => Geolocation.stop()
getLocation = async () =>
getLastLocation = async () =>
this.updateLocationState(await Geolocation.getLastLocation())

render() {
Expand All @@ -68,8 +75,8 @@ class App extends React.Component {
/>
<Button
style={style.button}
onPress={this.getLocation}
title="单次定位"
onPress={this.getLastLocation}
title="定位缓存"
/>
</View>
{Object.keys(location).map(key => (
Expand Down
27 changes: 27 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
platform :ios, '8.0'

# The target name is most likely the name of your project.
target 'RNAMapGeolocation' do

# Your 'node_modules' directory is probably in the root of your project,
# but if not, adjust the `:path` accordingly
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # Needed for debugging
'RCTAnimation', # Needed for FlatList and animations running on native UI thread
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

# Third party deps podspec link
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

pod 'react-native-amap-geolocation', path: '../lib/ios'
end
Loading

0 comments on commit d5b2af4

Please sign in to comment.