-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapsScreen.js
56 lines (56 loc) · 1.82 KB
/
MapsScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { Component } from 'react';
import { View, Linking } from 'react-native';
import MapView, { Marker, Callout } from 'react-native-maps';
// https://developers.google.com/maps/documentation/urls/guide
const URL = "https://www.google.com/maps/dir/?api=1&destination=";
export default class MapsScreen extends Component {
openGoogleMaps() {
const { navigation } = this.props;
// TODO FIXME. If 'NO-LATLNG' then there will be an error.
let latLng = navigation.getParam('latLng', 'NO-LATLNG');
let url = URL + latLng.latitude + "," + latLng.longitude;
Linking.canOpenURL(url).then(function (successMessage) {
Linking.openURL(url).catch((err) => {
// do nothing if openURL fails
});
}).catch(function (reason) {
// do nothing if cannot open url
});
}
render() {
const { navigation } = this.props;
// TODO FIXME. If 'NO-LATLNG' then there will be an error.
let latLng = navigation.getParam('latLng', 'NO-LATLNG');
// latLng param is passed from MoviesScreen and used to
// set initialRegion on MapView below.
let name = navigation.getParam('name', 'No theater found');
let address = navigation.getParam('address',
'No address found');
let phone = navigation.getParam('phone', '');
let description = address + ", " + phone;
return (<View style={
[{ flex: 1, justifyContent: 'center' },
{
flexDirection: 'row',
justifyContent: 'space-around',
padding: 10
}]
}>
<MapView style={[{ flex: 1 }]}
initialRegion={{
latitude: latLng.latitude,
longitude: latLng.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}>
<Marker key={name} coordinate={latLng}
title={name} description={description}>
<Callout alphaHitTest tooltip
onPress = {this.openGoogleMaps.bind(this)}
>
</Callout>
</Marker>
</MapView>
</View>);
}
}