geolocation doesn't work with Firefox

浪尽此生 提交于 2019-12-23 09:36:28

问题


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 ?


回答1:


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




回答2:


Maybe it is the same issue: firefox: navigator.geolocation.getCurrentPosition does not succeed anymore

If you are using linux, try another firefox version.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/19632436/geolocation-doesnt-work-with-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!