Open roughsoft opened 11 years ago
Related google group discussions:
Just curious if there is any update on this?
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!
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/
@pwlin that was amazing! thanks for this.
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.
@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
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 =(
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.
Im working on a mixed solution single webpage:
it will be great to get transparent code here native in node-webkit and use for example the macos location service (in desktop):
Checkout the browserlocation
request accuracy compared with the apple core location response (in the same iMac)
browserlocation:
core location:
It is not acceptable in any way, but if you use the getCurrentLocation from browser:
I insist, IMHO nw.js must give native support for geolocation ...
Note, using geolocation service from google i get unacceptable accuracies to (the same as browserlocation
service):
https://developers.google.com/maps/documentation/business/geolocation/
We get the better results using the core location from apple or the native browser geolocation support ...
Updates ??
nothing =(
It should be easily supported in 0.13. Will check it.
Still no support for this?
Can fake geolocation?
@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
@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
+1
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...)
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.