locate user javascript return default address

Viewed 124

I need to locate my users with high precision using javascript.

At the moment I am using this lib https://github.com/onury/geolocator

With the folowing options

var options = {
    enableHighAccuracy: true,
    timeout: 15000,
    maximumWait: 15000,     // max wait time for desired accuracy
    maximumAge: 0,          // disable cache
    desiredAccuracy: 30,    // meters
    fallbackToIP: false,    // fallback to IP if Geolocation fails or rejected
};

It's a little slow but most of the time working well.

But I have a geolocation issue from time to time, I do not really understand why but the output is:

{
    "latitude": 40.712742950000006,
    "longitude": -74.00595024412516,
    "formattedAddress": "New York City Hall, 260, Broadway, Civic Center, Manhattan Community Board 1, Manhattan, New York County, New York, 10000, United States of America",
    "country": "United States of America",
    "city": "Manhattan Community Board 1",
    "state": "New York",
    "zipcode": "10000",
    "streetName": "Broadway",
    "streetNumber": "260",
    "countryCode": "US",
    "neighbourhood": "",
    "provider": "openstreetmap",
}

Seems like a default position, but the script should use the browser location feature.

All users are executing the script from a mobile device

2 Answers

this might be a low internet connection problem probably. Please try to disable or remove

maximumWait: 15000

now try it without that and also set the timeout option to Infinity as realAlexBarge said.

Related