Question Detail

I am learning React Native app, Working on a Live Location Sharing App for Android and Ios Mobile Application. Where I 

want to show MapView to show geoLocation of mine (User). like below MapView Screen.

Get Current Location using React Native MapView

and show Marker of the location where user locate.

Get Current Location and Map Centered on Current Location with a Marker.

 

 


Thread Reply

Anonymous

- 1 months ago

To get Current Location in React Native you have to import Location from Expo.

import { Constants, Location, Permissions } from 'expo';

 

componentDidMount() {
  this._getLocationAsync();
  }

 

 _getLocationAsync = async () => {
   let { status } = await Permissions.askAsync(Permissions.LOCATION);
   if (status !== 'granted') {
     this.setState({
       locationResult: 'Permission to access location was denied',
       location,
     });
   }

   let location = await Location.getCurrentPositionAsync({});
console.Log("MYLIVELOCATION",""+JSON.stringify(location));
 };