Skip to content

Commit

Permalink
put notes on the map
Browse files Browse the repository at this point in the history
  • Loading branch information
K committed Oct 17, 2024
1 parent cdda27b commit cc37ca5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nr-app/src/components/Map.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {
allPlusCodesForRegion,
coordinatesToPlusCode,
plusCodeToCoordinates,
} from "@/utils/map.utils";
import { StyleSheet, View } from "react-native";

import MapView, { Marker } from "react-native-maps";
import { eventsSelectors } from "@/redux/slices/events.slice";
import { useAppSelector } from "@/redux/hooks";

export default function Map() {
const events = useAppSelector(eventsSelectors.selectAll);

return (
<View style={styles.mapContainer}>
<MapView
Expand All @@ -33,6 +38,17 @@ export default function Map() {
}}
>
<Marker coordinate={{ latitude: 52, longitude: 13 }} title="A marker" />

{events.map((event) => (
<Marker
coordinate={
Array.isArray(event.event.tags[1]) && event.event.tags[1][1]
? plusCodeToCoordinates(event.event.tags[1][1])
: null
}
title={`${new Date(event.event.created_at * 1000).toLocaleString()}: ${event.event.content}`}
/>
))}
</MapView>
</View>
);
Expand Down
18 changes: 18 additions & 0 deletions nr-app/src/utils/map.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ export function plusCodeToArrayPairs(plusCode: string): [string, string][] {
return pairs;
}

export function plusCodeToCoordinates(plusCode: string): {
latitude: number;
longitude: number;
} {
const decoded = OpenLocationCode.decode(plusCode);

console.log("as343JKC", decoded);
if (decoded) {
return {
latitude: decoded.latitudeHi,
longitude: decoded.longitudeHi,
};
} else {
console.error("Invalid Plus Code");
return null;
}
}

export function allPlusCodesForRegion({
latitude,
latitudeDelta,
Expand Down

0 comments on commit cc37ca5

Please sign in to comment.