Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Calculate distance between user location and fixed location

$
0
0

I am trying to calculate the distance between user's current location and specific location. In other words, I need the distance required for the user from their current location to the specific location.

Requirements:

  • I need to show user current location (DONE)
  • Use a location (in my case (24.41913107517948, 54.43699913714186) and put a marker on that location (DONE)
  • If the user current location is inside the radius, show success message, if the user current location is outside the radius, show error message with the required distance to the green radius.
const location = {    latitude: 24.41913107517948,    longitude: 54.43699913714186,    latitudeDelta: 0.09,    longitudeDelta: 0.035  }const [loc, setLoc] = useState({    latitudeDelta: 24.41913107517948,    longitudeDelta:  54.43699913714186,});<MapView    style={mapStyles}    mapType='hybrid'    provider={PROVIDER_GOOGLE}    region={location}><MapView.Circle                        key = { (loc.latitudeDelta + loc.longitudeDelta).toString() }                        center = { {                            latitude: loc.latitudeDelta,                            longitude: loc.longitudeDelta                        } }                        radius = { radius }                        strokeWidth = { 1 }                        strokeColor = { '#7fff00' }                        fillColor = { 'rgba(0,238,0,0.5)' }                /><Marker coordinate = {{latitude: 24.41913107517948,longitude: 54.43699913714186}}         pinColor = {"red"} // any color         /></MapView>

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>