Reputation: 9279
So, i use this code :
var options = {
enableHighAccuracy: true,
timeout: 2000,
maximumAge: 100
};
navigator.geolocation.getCurrentPosition(localizeMe, errorLocalize, options);
On the callback localizeMe, i do some success things, and errorLocalize show me an alert when this code doesn't work.
When i try this code on Chrome, it's ok, i haven't problem. But on firefox, i always have my alert error when i'm trying this code, the callback error is always call... Do you have any ideas ?
Upvotes: 6
Views: 3733
Reputation: 517
There is other way to do it, you can just use http service of google.
if you are using angular then first you will need to import this
import { Http, Headers, RequestOptions, Response } from '@angular/http';
or you can use other way according to your scripting language. then add this code in one of method where you are writing above 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 will subscribe the result of above http request you will get your required data in json format like this
{
"location": {
"lat": 21.1247647,
"lng": 79.04754489999999
},
"accuracy": 625
}
use it acc to your requirement ..happy coding
Upvotes: 0
Reputation: 636
On Windows it's broken too (at least on Windows 7 x64, haven't tested it yet on other versions). 23.0.1 is OK.
Upvotes: 0
Reputation: 519
geolocation has been broken on Firefox, on Linux and Mac, I believe, since v24.
There's an bug against Ubuntu here: https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/1231273
Upvotes: 2
Reputation: 199
Maybe it is the same issue: firefox: navigator.geolocation.getCurrentPosition does not succeed anymore
If you are using linux, try another firefox version.
Upvotes: 0