Geolocation does not work with Firefox

So, I am using this code:

var options = { enableHighAccuracy: true, timeout: 2000, maximumAge: 100 }; navigator.geolocation.getCurrentPosition(localizeMe, errorLocalize, options); 

In the localizeMe callback, I do some success things, and errorLocalize shows me a warning when this code does not work.

When I try to use this code in Chrome, this is normal, I have no problem. But in firefox, I always have my warning error, when I try to use this code, the callback error always causes ... Do you have any ideas?

+6
source share
4 answers

Geolocation was broken in Firefox, on Linux and Mac, I believe, starting with version v24.

There is an error here against Ubuntu: https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/1231273

+2
source

Perhaps this is the same problem: firefox: navigator.geolocation.getCurrentPosition no longer works

If you are using Linux, try another version of firefox.

0
source

On Windows, this also broke (at least on Windows 7 x64, has not tested it in other versions yet). 23.0.1 is fine.

0
source

There is another way to do this, you can just use the google http service.

if you use angular then first you will need to import this

 import { Http, Headers, RequestOptions, Response } from '@angular/http'; 

or you can use a different method according to your scripting language. then add this code to one of the methods where you write over the code

 let body = { enableHighAccuracy: true, timeout: 2000, maximumAge: 100 }; let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); this.http.post("https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY", body, headers).map((data: any) => data.json()); 

when you sign the result of the above http request, you will get the necessary data in json format, for example,

 { "location": { "lat": 21.1247647, "lng": 79.04754489999999 }, "accuracy": 625 } 

use it as per your requirement. happy coding

0
source

Source: https://habr.com/ru/post/956855/


All Articles