I need user to select location of an event.
Now what already works is opening the native maps (at least on android) - I can open the native maps through { Linking } from "react-native";
geo:24.669026,24.699024?z=6
However what I can't find how to make native maps prompt user to set some location and after some kind of confirmation?
I imagined something like return_url
with some sort of backlink to my application.
Or is this ONLY possible through embeding maps and using Google Maps API?
(I am trying to avoid billing, since all I want to do is to help user to find the coordinates and put them back to application, the application doesn't use the coordinates to do anything besides sending user to display them on they native maps)
so if I understood you correctly you want to show the user's current location on the map without paying to any third party, if that's the case you need to do the followings.
1. Get user latitude and longitude.
You can follow the below article for getting user latitude and longitude.
2. Show those latitudes and longitudes on the map using some marker.
So in this step, we will be using react-native-maps
and OpenStreetMap
.
Note: Do not change urlTemplate
in the UrlTile
Here is the reference for custom map tile from react-native-maps
https://github.com/react-native-maps/react-native-maps#tile-overlay-using-tile-server
import MapView, { UrlTile, Marker } from "react-native-maps";
const { width, height } = props;
const ASPECT_RATIO = width / height;
const LATITUDE_DELTA = 8; //Very high zoom level
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
const userCoords={{
latitude: number,
longitude: number
}};
<MapView
initialRegion={{
latitude: 51.1657,
longitude: 10.4515,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}
loadingEnabled
minZoomLevel={3}
maxZoomLevel={10}
showsIndoors={false}
showsTraffic={false}
showsBuildings={false}
showsScale={true}
>
<UrlTile
/**
* The url template of the tile server. The patterns {x} {y} {z} will be replaced at runtime
* For example, http://c.tile.openstreetmap.org/{z}/{x}/{y}.png
*/
urlTemplate={"http://c.tile.openstreetmap.org/{z}/{x}/{y}.png"}
/**
* The maximum zoom level for this tile overlay. Corresponds to the maximumZ setting in
* MKTileOverlay. iOS only.
*/
maximumZ={10}
/**
* flipY allows tiles with inverted y coordinates (origin at bottom left of map)
* to be used. Its default value is false.
*/
flipY={false}
/>
<Marker coordinate={userCoords}>
/**
* Your custom marker here
*/
</Marker>
</MapView>;