GithubHelp home page GithubHelp logo

Comments (22)

42void avatar 42void commented on May 7, 2024 12

Problem is solved if you remove enableHighAccuracy: true

from react-native-maps.

qrobin avatar qrobin commented on May 7, 2024 2

Could we guys somehow get the blue dot coords? It would be a perfect solution for tons of user location tracking problems. Because navigator.geolocation is not cool at all, and it's coords differ from the blue dot's ones..

from react-native-maps.

npomfret avatar npomfret commented on May 7, 2024 1

Do navigator.geolocation.getCurrentPosition work and navigator.geolocation.watchPosition work on android? I'm just getting a timeout error. I've got <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />in my manifest file, and I can see the users current position (the blue dot) on a map, but I can't programatically get the position.

from react-native-maps.

ockka avatar ockka commented on May 7, 2024 1

I’m having a similar issue. I can’t receive the initial position on Android via navigator.geolocation.getCurrentPosition because it will timeout. But I can receive the position from navigator.geolocation.watchPosition with Android. Currently I need to wait for the position before my component can be launched.

from react-native-maps.

tab1293 avatar tab1293 commented on May 7, 2024 1

Can confirm that I get a Location request timed out error on a S6 with this code:

componentWillMount() {
    this._setPosition();
}

_setPosition() {
    navigator.geolocation.getCurrentPosition((position) => {
        this.setState({
            position: position
        });
    }, (error) => {
        alert(error)
    }, {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000});
}

Android manifest has proper permission:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Is this an error with navigator.geolocation? Is there another library I can use for geolocation on Android devices?

from react-native-maps.

graywolf336 avatar graywolf336 commented on May 7, 2024

Sounds like that's async on android and sync on ios, but I could be wrong. Might be best to use region instead of initialRegion? That's just a guess though..

from react-native-maps.

lelandrichardson avatar lelandrichardson commented on May 7, 2024

@SHIEER I suspect this is an issue where onMapReady has not been called yet when you're setting state. This would only end up being an issue on android.

When I get a sec I can try and get this code working on my machine...

from react-native-maps.

ty-sang avatar ty-sang commented on May 7, 2024

@lelandrichardson Yes, it's only happen on Android. Thanks for your reply, I appreciate

from react-native-maps.

christopherdro avatar christopherdro commented on May 7, 2024

@SHIEER Are you receiving coordinates at all?
Also, have you added <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> to AndroidManifest.xml already?

from react-native-maps.

christopherdro avatar christopherdro commented on May 7, 2024

@SHIEER Things are working fine for me.
Closing this for now since we haven't heard back in a while.
Feel free to re-open it again if the problem persists. Thanks!

from react-native-maps.

npomfret avatar npomfret commented on May 7, 2024

I've debugged the java code and found that my device is not updating its GPS location very often. The last update was over 12 hours ago. So if I change my js code to allow navigator.geolocation.getCurrentPosition to return a very old value it at least returns something now.

I've no idea why the device is not updating the location. I can see a blue dot on a MapView so I'm sure the GPS is working. It's a new device, maybe I need to do something to it in order to make it work.

from react-native-maps.

jrichardlai avatar jrichardlai commented on May 7, 2024

@npomfret this is more a react-native question in the comments it says

 /**
   * Get the current position. This can return almost immediately if the location is cached or
   * request an update, which might take a while.
   *
   * @param options map containing optional arguments: timeout (millis), maximumAge (millis) and
   *        highAccuracy (boolean)
   */

Its possible you have to move around to update the location.

from react-native-maps.

npomfret avatar npomfret commented on May 7, 2024

Thanks. Looks like there's something wrong with the device, its only updating the gps very rarely, so yes a very large value for max age works around the issue.

from react-native-maps.

christopherdro avatar christopherdro commented on May 7, 2024

Use distance filter option on the watchPosition method.

from react-native-maps.

xvalentino avatar xvalentino commented on May 7, 2024

Just a note, if you're on an emulator make sure you always have set your location.

from react-native-maps.

AugustoAleGonZhipCode avatar AugustoAleGonZhipCode commented on May 7, 2024

@tab1293 Probably a newbie question. But how can I get access to the position? I am just starting on React Native enviroment. I hope you can answer me.

from react-native-maps.

koz avatar koz commented on May 7, 2024

@AugustoAleGonZhipCode Check this section of the React Native docs https://facebook.github.io/react-native/docs/geolocation.html

from react-native-maps.

petrovakd avatar petrovakd commented on May 7, 2024

really, it would be great! it's quite strange that we can see this dot but don't have access to its coords

from react-native-maps.

lone-cloud avatar lone-cloud commented on May 7, 2024

Not sure what ppl's problem is with 42void's solution of removing enableHighAccuracy: true. It seems very counter-intuitive, but somehow it's been the only solution to get my map to center on the blue dot coords. Surprisingly my geolocation is much more precise without it (just luck?).

from react-native-maps.

qrobin avatar qrobin commented on May 7, 2024

@hoboman313 oh really??
Need to be checked : )

from react-native-maps.

joelGarcia93 avatar joelGarcia93 commented on May 7, 2024

this code work perfectly in the cellphone (Im not using emulator)

import React, { Component } from 'react';
import {
Text,
View
} from 'react-native';

export default class App extends Component<{}> {

constructor(props) {
super(props);
this.state = {
initialPosition: 'unknown'
};
}

componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
var positionCoordinates = JSON.stringify(position);
this.setState({initialPosition: positionCoordinates});
},
(error) => alert(error.message),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);

}

render() {
return (

initial: { this.state.initialPosition }

);
}
}

from react-native-maps.

amit13091992 avatar amit13091992 commented on May 7, 2024
  state = {
    focusedLocation: {
      latitude: 18.7934829,
      longitude: 98.9867401,
      latitudeDelta: 0.0122,
      longitudeDelta: Dimensions.get("window").width / Dimensions.get("window").height * 0.0122,
      locationChosen: false
    }
  }  

getLocationHandler = () => {
    Geolocation.getCurrentPosition(pos => {
      console.log('lat', pos.coords.latitude);
      console.log('lng', pos.coords.longitude);
      const coordsEvent = {
        nativeEvent: {
          coordinate: {
            latitude: pos.coords.latitude,
            longitude: pos.coords.longitude
          }
        }
      };
      console.log(" co-ordinates " + JSON.stringify(coordsEvent));
      this.pickLocationHandler(coordsEvent);
    },
      err => {
        console.log(err);
        alert("Fetching the Position failed, please pick one manually!");
      })
  }
  pickLocationHandler = event => {
    const coords = event.nativeEvent.coordinate;
    console.log("pickLocationHandler Co-Ordinates: " + JSON.stringify(event.nativeEvent.coordinate));
    this.map.animateToRegion({
      ...this.state.focusedLocation,
      latitude: coords.latitude,
      longitude: coords.longitude
    });
    this.setState(prevState => {
      return {
        focusedLocation: {
          ...prevState.focusedLocation,
          latitude: coords.latitude,
          longitude: coords.longitude
        },
        locationChosen: true
      };
    });
  };

render() {
    return (
<MapView
          initialRegion={this.state.focusedLocation}
          onMapReady={this.getLocationHandler}
</MapView>
);
}

by using onMapReady() method of MapView, you can set the map region automatically based on your current region and location.

from react-native-maps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.