-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "your location" marker and base map viewport on courier location …
…and your location
- Loading branch information
frederik-oestergaard
committed
Feb 8, 2021
1 parent
d054d5b
commit 3ca8f89
Showing
8 changed files
with
701 additions
and
15,735 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,7 @@ npm-debug.* | |
*.orig.* | ||
web-build/ | ||
|
||
firebaseServiceAccountKey.json | ||
|
||
# macOS | ||
.DS_Store |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,80 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet, Image } from 'react-native'; | ||
import MapView, { Marker } from 'react-native-maps'; | ||
import { Text, View } from '../components/Themed'; | ||
import * as React from "react"; | ||
import { StyleSheet, Image } from "react-native"; | ||
import MapView, { Marker } from "react-native-maps"; | ||
import { Text, View } from "../components/Themed"; | ||
|
||
export interface IMarker { | ||
latlng: { | ||
latitude: number; | ||
longitude: number; | ||
}; | ||
title: string; | ||
description: string; | ||
} | ||
|
||
export interface TrackingMapProps { | ||
marker: {latlng: { | ||
latitude: number, | ||
longitude: number, | ||
}, | ||
title: string, | ||
description: string, | ||
} | ||
yourLocation: IMarker; | ||
courier: IMarker; | ||
} | ||
|
||
const TrackingMap: React.FC<TrackingMapProps> = ({marker}) => { | ||
const TrackingMap: React.FC<TrackingMapProps> = ({ courier, yourLocation }) => { | ||
function getRegion(pos1: IMarker, pos2: IMarker) { | ||
const midPointLat = (pos1.latlng.latitude + pos2.latlng.latitude) / 2; | ||
const midPointLong = (pos1.latlng.longitude + pos2.latlng.longitude) / 2; | ||
return { | ||
latitude: midPointLat, | ||
longitude: midPointLong, | ||
latitudeDelta: | ||
Math.abs(pos1.latlng.latitude - pos2.latlng.latitude) * 1.5, | ||
longitudeDelta: | ||
Math.abs(pos1.latlng.longitude - pos2.latlng.longitude) * 1.5, | ||
}; | ||
} | ||
|
||
return ( | ||
<> | ||
<Text style={styles.title}>Live tracking!</Text> | ||
<MapView style={styles.map} > | ||
|
||
<Marker | ||
coordinate={marker.latlng} | ||
title={marker.title} | ||
description={marker.description} | ||
> | ||
<Image | ||
source={require('../assets/images/player.png')} | ||
style={{width: 26, height: 28}} | ||
resizeMode="contain" | ||
/> | ||
</Marker> | ||
|
||
<MapView style={styles.map} region={getRegion(courier, yourLocation)}> | ||
<Marker | ||
coordinate={yourLocation.latlng} | ||
title={"Your location"} | ||
description={yourLocation.description} | ||
> | ||
<Image | ||
source={require("../assets/images/house.png")} | ||
style={{ width: 26, height: 26 }} | ||
resizeMode="contain" | ||
/> | ||
</Marker> | ||
<Marker | ||
coordinate={courier.latlng} | ||
title={courier.title} | ||
description={courier.description} | ||
> | ||
<Image | ||
source={require("../assets/images/player.png")} | ||
style={{ width: 26, height: 26 }} | ||
resizeMode="contain" | ||
/> | ||
</Marker> | ||
</MapView> | ||
</> | ||
); | ||
} | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
width: '100%', | ||
height: '100%' | ||
width: "100%", | ||
height: "100%", | ||
}, | ||
title: { | ||
fontSize: 20, | ||
fontWeight: 'bold', | ||
fontWeight: "bold", | ||
}, | ||
map: { | ||
width: '100%', | ||
height: '50%' | ||
width: "100%", | ||
height: "50%", | ||
}, | ||
}); | ||
|
||
export default TrackingMap; | ||
export default TrackingMap; |
Oops, something went wrong.