How do I get Geolocation API to work in Dartium?

微笑、不失礼 提交于 2019-12-02 04:25:07

问题


I'm trying to test in Dartium browser using the Geolocation API. In particular I try doing the following

window.navigator
  .geolocation.getCurrentPosition()
    ..then((pos) {

      window.alert(pos.toString());
    })
    ..catchError((PositionError error) {
      window.alert("Error code: ${error.code}, Error message: ${error.message}");
    })
    ..whenComplete(() => window.alert("complete"))
    ;

Ignoring the fact I'm using window.alert here, All I get is an error with the following message "Error code: 2, Error message: Network location provider at 'https://www.googleapis.com/' : Returned error code 400."

However the same code works in Google Chrome when I use "pub serve". It also works with Firefox. How do I overcome this error, and get it to work in Dartium? Is it even possible?

UPDATE

I took a look at the 403 bug and tried using the fix specified on this page http://www.chromium.org/developers/how-tos/api-keys, and when I first tried this, I got my credentials and setting wrong, I was getting a 403 error, but once that was resolved, and all the APIs enabled, plus the environment settings of

GOOGLE_API_KEY
GOOGLE_DEFAULT_CLIENT_ID
GOOGLE_DEFAULT_CLIENT_SECRET

I was back to "Network location provider at 'https://www.googleapis.com/' : Returned error code 400.", so I conclude it isn't the same issue. Though if someone can prove me wrong, I'd be happy.

FURTHER UPDATE

This is a bug. I've answered my own question below.


回答1:


Maybe you are running into this issue

Geolocation giving 403 error

Should be fixable by providing Google API keys for Dartium




回答2:


This is a bug.

I posted this question on https://groups.google.com/a/dartlang.org/forum/#!topic/web/UMJHJlQH7wc, where Seth Ladd asked me to open a bug.

I've opened a bug for this, https://code.google.com/p/dart/issues/detail?id=15866. So hopefully this will be resolved soon.



来源:https://stackoverflow.com/questions/20824595/how-do-i-get-geolocation-api-to-work-in-dartium

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