/** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, Dimensions, Animated, TouchableOpacity, } = React; var MapView = require('react-native-maps'); var PriceMarker = require('./components/PriceMarker'); var { width, height } = Dimensions.get('window'); const LATITUDE = 37.78825; const LONGITUDE = -122.4324; const LATD = LATITUDE - 38.89399; const LNGD = LONGITUDE + 77.03659; const LATITUDE_DELTA = 0.0922; const LONGITUDE_DELTA = 0.1218; var MapViewTest = React.createClass({ getInitialState() { const scale = new Animated.Value(1); const latitudeDelta = scale.interpolate({ inputRange: [1, 2], outputRange: [LATITUDE_DELTA, LATITUDE_DELTA * 0.6], }); const longitudeDelta = scale.interpolate({ inputRange: [1, 2], outputRange: [LONGITUDE_DELTA, LONGITUDE_DELTA * 0.6], }); return { val: new Animated.Value(1), scale, region: new Animated.Region({ latitude: LATITUDE, longitude: LONGITUDE, latitudeDelta: latitudeDelta, longitudeDelta: longitudeDelta, }), markers: [], coord: { latitude: LATITUDE, longitude: LONGITUDE, }, }; }, onRegionChange(region) { //console.log("onRegionChange", region); this.state.region.setValue(region); //this.setState({ region }); }, onAnimate() { var { val } = this.state; Animated.sequence([ Animated.timing(val, { toValue: 0, duration: 500 }), Animated.timing(val, { toValue: 1, duration: 500 }), ]).start(); }, onAddMarker() { var coordinate = { latitude: LATITUDE + LATITUDE_DELTA * (Math.random() - 0.5), longitude: LONGITUDE + LONGITUDE_DELTA * (Math.random() - 0.5), }; var markers = [...this.state.markers, coordinate]; if (markers.length > 5) { markers = markers.slice(1); } this.setState({ markers }); }, onAnimateZoom() { var { scale, region } = this.state; var toValue = scale.__getValue() > 1 ? 1 : 2; Animated.parallel([ Animated.spring(region.latitude, { toValue: LATITUDE + LATITUDE_DELTA * (Math.random() - 0.5), }), Animated.spring(region.longitude, { toValue: LONGITUDE + LONGITUDE_DELTA * (Math.random() - 0.5), }), Animated.spring(scale, { toValue, }), ]).start(); }, onMarkerMove() { this.setState({ coord: { latitude: LATITUDE + LATITUDE_DELTA * (Math.random() - 0.5), longitude: LONGITUDE + LONGITUDE_DELTA * (Math.random() - 0.5), }, }) }, onAnimateMapRegion() { this.refs.map.refs.node.animateToRegion({ latitude: LATITUDE + LATITUDE_DELTA * (Math.random() - 0.5), longitude: LONGITUDE + LONGITUDE_DELTA * (Math.random() - 0.5), latitudeDelta: LATITUDE_DELTA, longitudeDelta: LONGITUDE_DELTA, }, 100); }, onZoomToFit() { this.refs.map.refs.node.fitToElements(true); }, render() { return ( console.log("Map::onRegionChangeComplete", e.nativeEvent)} onPress={(e) => console.log("Map::onPress", e.nativeEvent)} onLongPress={(e) => console.log("Map::onLongPress", e.nativeEvent)} onMarkerPress={(e) => console.log("Map::onMarkerPress", e.nativeEvent)} onMarkerSelect={(e) => console.log("Map::onMarkerSelect", e.nativeEvent)} onMarkerDeselect={(e) => console.log("Map::onMarkerDeselect", e.nativeEvent)} onCalloutPress={(e) => console.log("Map::onCalloutPress", e.nativeEvent)} onMapPress={(e) => console.log("Map::onMapPress", e.nativeEvent)} > console.log("Marker::onPress", e.nativeEvent)} onCalloutPress={(e) => console.log("Marker::onCalloutPress", e.nativeEvent)} > console.log("Callout::onPress", e.nativeEvent)} > Well hello there... {this.state.markers.map((coord, i) => ( console.log("Marker::onPress", e.nativeEvent)} onCalloutPress={(e) => console.log("Marker::onCalloutPress", e.nativeEvent)} > console.log("Callout::onPress", e.nativeEvent)} > Well hello there... ))} Add Marker Animate Zoom Move Marker Animate Map Region Fit To Elements ); }, }); var styles = StyleSheet.create({ map: { height: 350, margin: 10, borderWidth: 1, borderColor: '#000000', }, row: { flexDirection: 'row', justifyContent: 'space-between', }, textInput: { width: 150, height: 20, borderWidth: 0.5, borderColor: '#aaaaaa', fontSize: 13, padding: 4, }, changeButton: { alignSelf: 'center', marginTop: 5, padding: 3, borderWidth: 0.5, borderColor: '#777777', }, red: { width: 50, height: 50, backgroundColor: 'red', }, blue: { width: 50, height: 50, backgroundColor: 'blue', }, callout: { //flex: 0, //flexDirection: 'column', //position: 'absolute', //flex: 0, //backgroundColor: '#fff', //width: 100, //height: 100, }, }); module.exports = MapViewTest; AppRegistry.registerComponent('rn_mapview', () => MapViewTest);