nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.3k stars 3.88k forks source link

any plan about Geolocation #236

Open roughsoft opened 11 years ago

roughsoft commented 11 years ago

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

xverges commented 10 years ago

Related google group discussions:

andrewthornton commented 10 years ago

Just curious if there is any update on this?

sdog869 commented 10 years ago

It would be nice if we could specify the permission in the manifest and not have to ask the user for this, I think it's a jarring experience to the user in app. Thanks!

pwlin commented 10 years ago

It is highly probable that the desktop machine running your node-webkit app does not have GPS hardware capabilities. In that case you just have to tap into the same Google Geolocation API as navigator.geolocation.getCurrentPosition, namely, a simple xmlhttp call to:

https://maps.googleapis.com/maps/api/browserlocation/json?browser=chromium&sensor=true

which will return a json string such as:

{
 "accuracy" : XXXX,
 "location" : {
   "lat" : XX.XX,
   "lng" : XX.XX
 },
 "status" : "OK"
}

Now you can write your own getCurrentPosition()

navigator.geolocation = {};
navigator.geolocation.getCurrentPosition = function(callback) {
    $.get('https://maps.googleapis.com/maps/api/browserlocation/json?browser=chromium&sensor=true', function(data) { 
        var position = {
            coords : {
                latitude : data.location.lat,
                longitude : data.location.lng
            }
        };
        callback(position);
    });
};

Instead of Google Geolocation API, you can also use

http://freegeoip.net/json/
aalaap commented 10 years ago

@pwlin that was amazing! thanks for this.

brettfattori commented 10 years ago

That's awesome. I'll use that until there is native support for GeoLocation. I'm okay with a system level prompt for permissions, but it would be nice to be able to "remember" what their choice was and use that so it doesn't ask again.

sgsaravana commented 9 years ago

@pwlin : Thanks for that. You can use the following code to get the map image with the coordinates

function showPosition(position) {
    var latlon = position.coords.latitude + "," + position.coords.longitude;
    var img_url = "http://maps.googleapis.com/maps/api/staticmap?center=
    "+latlon+"&zoom=14&size=400x300&sensor=false";
    document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";
}

And use this if you want an interactive map: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation_map_script

outaTiME commented 9 years ago

Any plan for this feature ???

For now im using the @pwlin solution the navigator.geolocation.watchPosition and navigator.geolocation.getCurrentPosition no asking for permissions then ... nothing happens =(

shaynem commented 9 years ago

Why wouldn't you just use a http call to one of the many Geolocation services or use a npm package with maxmind db

It's better then a browser warning asking for the users location which html5 gives. On 11 May 2015 4:06 am, "Ariel Falduto" notifications@github.com wrote:

Any plan for this feature ???

— Reply to this email directly or view it on GitHub https://github.com/nwjs/nw.js/issues/236#issuecomment-100675967.

outaTiME commented 9 years ago

Im working on a mixed solution single webpage:

  1. node-webkit desktop app pointing to remote webpage (where the http call is fine).
  2. web page in browsers where the html5 geolocation feature may be use the GPS on devices with this capabilities.

it will be great to get transparent code here native in node-webkit and use for example the macos location service (in desktop):

screen shot 2015-05-12 at 14 16 00

outaTiME commented 9 years ago

Checkout the browserlocation request accuracy compared with the apple core location response (in the same iMac)

browserlocation:

screen shot 2015-05-31 at 15 39 48

core location:

screen shot 2015-05-31 at 15 41 18

It is not acceptable in any way, but if you use the getCurrentLocation from browser:

screen shot 2015-05-31 at 15 46 19

I insist, IMHO nw.js must give native support for geolocation ...

outaTiME commented 9 years ago

Note, using geolocation service from google i get unacceptable accuracies to (the same as browserlocation service):

https://developers.google.com/maps/documentation/business/geolocation/

screen shot 2015-05-31 at 16 01 50

We get the better results using the core location from apple or the native browser geolocation support ...

outaTiME commented 9 years ago

Updates ??

luannpeixe commented 8 years ago

nothing =(

rogerwang commented 8 years ago

It should be easily supported in 0.13. Will check it.

tomekmarchi commented 8 years ago

Still no support for this?

hstarorg commented 8 years ago

Can fake geolocation?

luannpeixe commented 8 years ago

@rogerwang Yes, navigator.geolocation work now. But generate error!

PS: Tested on 0.14 and 0.15 version...

See:

PositionError {code: 2, message: "Network location provider at 'https://www.googleapis.com/' : Returned error code 400."} code : 2 message : "Network location provider at 'https://www.googleapis.com/' : Returned error code 400." proto : PositionError

jtg-gg commented 8 years ago

@rogerwang I've a working implementation using OS geo-location capability, but it will only work on Win 8 or newer and OSX, here is my pull request https://github.com/nwjs/chromium.src/pull/20

The google chrome implementation, will need google api key, so I implement it using OS geo-location capability

blaremc commented 7 years ago

+1

pwlin commented 5 years ago

Just a follow up to my earlier workaround from 2014:

Currently, Google Geolocation API url returns 404 and freegeoip.net requires registration and api keys.

You can use

https://freegeoip.app/json/

as an alternative to get latitude and longitude of your current position as it does not involve any registration or api key. (No affiliation, just a free service I wanted to mention, so Caveat Emptor and all that jazz...)