forked from react-native-maps/react-native-maps
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added animateToNavigation method to MapView (react-native-maps#2049)
* added animateToNavigation method to MapView * Added AnimatedNavigation example * Updated Fork * Deleted IDE files and Unnecessary .class files
- Loading branch information
Showing
15 changed files
with
278 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>example-android</name> | ||
<comment>Project example-android created by Buildship.</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
</projectDescription> |
Binary file added
BIN
+2.51 KB
...roid/app/bin/src/main/java/com/airbnb/android/react/maps/example/ExampleApplication.class
Binary file not shown.
Binary file added
BIN
+1.13 KB
...le/android/app/bin/src/main/java/com/airbnb/android/react/maps/example/MainActivity.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import React, { Component } from 'react'; | ||
|
||
import { | ||
View, | ||
StyleSheet, | ||
TouchableOpacity, | ||
Text, | ||
} from 'react-native'; | ||
|
||
import MapView from 'react-native-maps'; | ||
import carImage from './assets/car.png'; | ||
|
||
export default class NavigationMap extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
prevPos: null, | ||
curPos: { latitude: 37.420814, longitude: -122.081949 }, | ||
curAng: 45, | ||
latitudeDelta: 0.0922, | ||
longitudeDelta: 0.0421, | ||
}; | ||
this.changePosition = this.changePosition.bind(this); | ||
this.getRotation = this.getRotation.bind(this); | ||
this.updateMap = this.updateMap.bind(this); | ||
} | ||
|
||
changePosition(latOffset, lonOffset) { | ||
const latitude = this.state.curPos.latitude + latOffset; | ||
const longitude = this.state.curPos.longitude + lonOffset; | ||
this.setState({ prevPos: this.state.curPos, curPos: { latitude, longitude } }); | ||
this.updateMap(); | ||
} | ||
|
||
getRotation(prevPos, curPos) { | ||
if (!prevPos) return 0; | ||
const xDiff = curPos.latitude - prevPos.latitude; | ||
const yDiff = curPos.longitude - prevPos.longitude; | ||
return (Math.atan2(yDiff, xDiff) * 180.0) / Math.PI; | ||
} | ||
|
||
updateMap() { | ||
const { curPos, prevPos, curAng } = this.state; | ||
const curRot = this.getRotation(prevPos, curPos); | ||
this.map.animateToNavigation(curPos, curRot, curAng); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={styles.flex}> | ||
<MapView | ||
ref={(el) => (this.map = el)} | ||
style={styles.flex} | ||
minZoomLevel={15} | ||
initialRegion={{ | ||
...this.state.curPos, | ||
latitudeDelta: this.state.latitudeDelta, | ||
longitudeDelta: this.state.longitudeDelta, | ||
}} | ||
> | ||
<MapView.Marker | ||
coordinate={this.state.curPos} | ||
anchor={{ x: 0.5, y: 0.5 }} | ||
image={carImage} | ||
/> | ||
</MapView> | ||
<View style={styles.buttonContainerUpDown}> | ||
<TouchableOpacity | ||
style={[styles.button, styles.up]} | ||
onPress={() => this.changePosition(0.0001, 0)} | ||
> | ||
<Text>+ Lat</Text> | ||
</TouchableOpacity> | ||
<TouchableOpacity | ||
style={[styles.button, styles.down]} | ||
onPress={() => this.changePosition(-0.0001, 0)} | ||
> | ||
<Text>- Lat</Text> | ||
</TouchableOpacity> | ||
</View> | ||
<View style={styles.buttonContainerLeftRight}> | ||
<TouchableOpacity | ||
style={[styles.button, styles.left]} | ||
onPress={() => this.changePosition(0, -0.0001)} | ||
> | ||
<Text>- Lon</Text> | ||
</TouchableOpacity> | ||
<TouchableOpacity | ||
style={[styles.button, styles.right]} | ||
onPress={() => this.changePosition(0, 0.0001)} | ||
> | ||
<Text>+ Lon</Text> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
flex: { | ||
flex: 1, | ||
width: '100%', | ||
}, | ||
buttonContainerUpDown: { | ||
...StyleSheet.absoluteFillObject, | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
}, | ||
buttonContainerLeftRight: { | ||
...StyleSheet.absoluteFillObject, | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
}, | ||
button: { | ||
backgroundColor: 'rgba(100,100,100,0.2)', | ||
position: 'absolute', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
borderRadius: 20, | ||
height: 50, | ||
width: 50, | ||
}, | ||
up: { | ||
alignSelf: 'flex-start', | ||
}, | ||
down: { | ||
alignSelf: 'flex-end', | ||
}, | ||
left: { | ||
alignSelf: 'flex-start', | ||
}, | ||
right: { | ||
alignSelf: 'flex-end', | ||
}, | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>react-native-maps-lib</name> | ||
<comment>Project react-native-maps-lib created by Buildship.</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
</projectDescription> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters