And Location Services
Welcome to JaxNode
This Saturday at Availity
"Pilots are never lost.
Sometimes they are
temporarily disoriented, but they are never lost."
Old Pilot Joke
// Get current position
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(pos => {
console.log(`Lat: ${pos.coords.latitude} & Long: ${pos.coords.longitude}`)
});
}
// Get updated position
const geoOptions {
enableHighAccuracy: true,
maximumAge : 30000,
timeout : 27000
};
if ("geolocation" in navigator) {
const wpid = navigator.geolocation.watchPosition(geoSuccess, geoError, geoOptions);
}
function geoSuccess(pos) {
console.log(`Lat: ${pos.coords.latitude} & Long: ${pos.coords.longitude}`)
}
function geoError() {
console.error('An error occurred');
}
// distance function from GeoDataSource.com (C) All Rights Reserved 2015
function distance(lat1, lon1, lat2, lon2, unit) {
const radlat1 = Math.PI * lat1/180;
const radlat2 = Math.PI * lat2/180;
const theta = lon1-lon2;
const radtheta = Math.PI * theta/180;
let dist = Math.sin(radlat1) * Math.sin(radlat2)
+ Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
dist = Math.acos(dist);
dist = dist * 180/Math.PI;
dist = dist * 60 * 1.1515;
if (unit=="K") {
dist = dist * 1.609344;
}
if (unit=="N") {
dist = dist * 0.8684;
}
return dist;
}
Haversine Algorithm
<MapView
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
constructor() {
this.state.region = {
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
};
}
onRegionChange(region) {
this.setState({ region });
}
render() {
return (
<MapView
region={this.state.region}
onRegionChange={this.onRegionChange}
/>
);
}
<MapView
region={this.state.region}
onRegionChange={this.onRegionChange}
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.latlng}
title={marker.title}
description={marker.description}
/>
))}
</MapView>