Its seems like in new chrome version on MacOs on Linux Mint and on Windows
geolocations doesnt works!
Its returns error:
"ERROR(2): Network location provider at 'https://www.googleapis.com/' : Returned error code 403."
Does anyone has same problem?
Must be a bug in the latest version of Chrome, also happens in the page of Google Maps API: https://developers.google.com/maps/documentation/javascript/examples/map-geolocation
Hopefully it will be fixed fast.
Edited: Try now, it works :)
Apparently this API has been forbidden access from insecure locations see here
I filed a bug ticket here: https://productforums.google.com/forum/?utm_medium=email&utm_source=footer#!msg/chrome/q7B6gjCr1ps/Y9DEXPZ-_HYJ
Feel free to comment there, star it, etc.
For future queries:
Starting with Chrome 50, Chrome no longer supports obtaining the user’s location using the HTML5 Geolocation API from pages delivered by non-secure connections. This means that the page that’s making the Geolocation API call must be served from a secure context such as HTTPS.
https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only?hl=en
This will break your web apps on chrome if you're not using HTTPS.
i didn't get any solution for "Returned error code 403" but i found one solution to get current location if google api fails
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
current_location_lat = position.coords.latitude;
current_location_lon = position.coords.longitude;
}, function (error) {
//if error occurred by google api
$.getJSON("http://ipinfo.io", function (ipinfo) {
var latLong = ipinfo.loc.split(",");
current_location_lat = latLong[0];
current_location_lon = latLong[1];
});
});
} else {
// Browser doesn't support Geolocation
alert("Error: Your browser doesn\'t support geolocation");
}
Related
For some reason suddenly when calling navigator.geolocation.getCurrentPosition() I get this error:
Network location provider at 'https://www.googleapis.com/' : Returned error code 403.
It used to work perfectly yesterday! Could there be anything with their servers??
It appears it is back up now. But before I realized it was working, I used another way to get location data as recommended by another user on reddit.com
var latLong;
$.getJSON("http://ipinfo.io", function(ipinfo){
console.log("Found location ["+ipinfo.loc+"] by ipinfo.io");
latLong = ipinfo.loc.split(",");
});
Source: https://www.reddit.com/r/webdev/comments/3j8ipj/anyone_else_had_issues_with_the_html5_geolocation/
This happens for me too on idoco.github.io/map-chat
I suspect that this is related the the changes google planed for Deprecating Powerful Features on Insecure Origins it seems that some changes were done in the last few days in this chromium Issue 520765: Deprecation and removal of powerful features on insecure origins
Can you test your site over https to confirm that?
In the meanwhile I found this api usage as a workaround on this repo:
$.getJSON("http://ipinfo.io", function(doc){
var latlong = doc.loc.split(",")
setUserLocation(parseFloat(latlong[0]), parseFloat(latlong[1]));
getLocation(parseFloat(latlong[0]), parseFloat(latlong[1])).then(function(res){
userLocationName = res
})
initialiseEventBus();
map.panTo(userLocation);
}, function(err) {
setUserLocation(Math.random()*50, Math.random()*60);
userLocationName = "unknown.na"
initialiseEventBus();
map.panTo(userLocation);
})
I had the same issue, you have to check your developer dashboard and make sure that your API key has no usage restrictions or warnings.
i am trying to get user current position in mobile web application
my app work in all android telephone device except samsung galaksy s2 telephone device ..
it give errror POSITION UNAVAILABLE error
this is demo link.you can view source
this is code
navigator.geolocation.getCurrentPosition(handle_geolocation_query1, handle_errors) ;
function handle_errors(error) {
switch (error.code) {
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query1(position) {
$('#map_canvas').gmap('addMarker', {
'id':'m_1',
'position': new google.maps.LatLng(position.coords.latitude,position.coords.longitude),
'bounds': true,
'icon': 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/images/gpsloc.png'
}).click(function () {
$('#map_canvas').gmap('openInfoWindow',{ 'content': '<font color="#2a2a2a" size="4">Location </font><br/><font color="#4a4a4a">Your current location</font>' }, this);
});
var map = $('#map_canvas').gmap('get', 'map');
map.setZoom(14);
map.setCenter(new google.maps.LatLng(41.01802007732287, 28.971880674362183));
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
}
edited:
i used phonegap to produce android apk file
when i work this apk file application it give error POSITION UNAVAILABLE error but when i call this page from web it works it does not give error ... this is web link and you can download apk from here
Your code is working fine in browser but not in mobile.
On checking your source code it seems you're specifying the sensor parameter as false.
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
You missed this while checking the documentation.
Specifying the Sensor Parameter
Use of the Google Maps API requires that you indicate whether your
application is using a sensor (such as a GPS locator) to determine the
user's location. This is especially important for mobile devices.
Applications must pass a required sensor parameter to the tag
when including the Maps API javascript code, indicating whether or not
your application is using a sensor device.
Applications that determine the user's location via a sensor must pass
sensor=true when loading the Maps API JavaScript.
Hope you understand.
On my device, I had my settings for Location mode set to "Device only".
In this case, I wasn't able to get a good connection of location and hence get Position Unavailable.
I change my Settings > Location > Mode and change it to High Accuracy.
It took me a lot of days to get this problem to work unknowingly that the problem is in the device itself. I did my best capability to fix the codes, and even traced back to the plugin's code.
Please respect my post. Some people might have this problem as well. Thank you.
I had the same error with Messenger webview, the location for Messenger was denied in phone settings so the error was resolved after allowing the location sharing for the Messenger app.
I've written a web app for Firefox Mobile / Firefox OS. My app uses geolocation.
It worked well when I tested it with Firefox for Android and the FFOS simulator add-on by visiting the web address of the application. Recently I've passed the Firefox Marketplace review and my app is installable on FFOS and Firefox for Android. To my surprise, when I installed and ran it, geolocation didn't work.
Here's an excerpt from the .webapp file:
"permissions": {
"geolocation": {
"description": "Required for ....."
}
}
Here's the relevant part of JS:
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(positionFound, positionNotFound, {
enableHighAccuracy: false,
maximumAge: 3600000
});
}
else {
$('#location').html('No geolocation support');
}
The else block is not executed, so JS detects that geolocation exists, but the callback is never called, and the GPS icon never blinks.
The app still works and positionFound() is called properly when accessed via its URL, not as an installed app.
How can I make it geolocate after installation?
The following code works for us, however GPS functionality is severely limited on the Geeksphone FFOS 1.2 nightly builds as well as aGPS on FFOS 1.0 (time to first fix ~ 5min). The geoLocation API requires frequent reboots on our devices. For us, FFOS 1.1 worked best so far. Try to use one of the existing GPS apps like "gpsDashboard" before starting your app. This way you know your phone is working.
function geo_success(position) {
alert(position.coords.longitude);
}
function geo_error() {
alert("Sorry, no position available.");
}
var geo_options = {
enableHighAccuracy: true,
maximumAge : 300000,
timeout : 270000
};
navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
Do your callback functions work properly with fake data?
Here's a post on the Mozilla Hacks Blog that discusses geolocation tips and tricks, as well as limitations with some of the developer devices:
https://hacks.mozilla.org/2013/10/who-moved-my-geolocation/
Just starting to get into HTML 5 and an testing out geo location...liking it so far. I am hitting a bit of a speed bump though...when I try to get my geo location, chrome automatically blocks the page from getting my location. This does not happen at other sites such as the site below:
http://html5demos.com/geo
The scripts I'm using:
<script type="text/javascript" JavaScript" SRC="geo.js"></script>
<script type="text/javascript" JavaScript" SRC="Utility.js"></script>
<script type="text/javascript" JavaScript" SRC="jquery.js"></script>
<script type="text/javascript" JavaScript" SRC="modernizr.js"></script>
function get_location() {
if (geo_position_js.init()) {
geo_position_js.getCurrentPosition(show_map, handle_error);
}
}
function show_map(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("lat:" + latitude + " long:" + longitude);
}
function handle_error(err) {
alert(err.code);
if (err.code == 1) {
// user said no!
}
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(show_map, handle_error);
} else {
error('not supported');
}
I am testing this out from a local directory on my machine, so there isn't really a "domain" like "http://whatever.com/mytestpage.html". Is this why I am not getting prompted? If so, is it possible to force the browswer to request permission to get the user's geo location and is it possible in my scenario?
There's some sort of security restriction in place in Chrome for using geolocation from a file:/// URI, though unfortunately it doesn't seem to record any errors to indicate that. It will work from a local web server. If you have python installed try opening a command prompt in the directory where your test files are and issuing the command:
python -m SimpleHTTPServer
It should start up a web server on port 8000 (might be something else, but it'll tell you in the console what port it's listening on), then browse to http://localhost:8000/mytestpage.html
If you don't have python there are equivalent modules in Ruby, or Visual Web Developer Express comes with a built in local web server.
None of the above helped me.
After a little research I found that as of M50 (April 2016) - Chrome now requires a secure origin (such as HTTPS) for Geolocation.
Deprecated Features on Insecure Origins
The host "localhost" is special b/c its "potentially secure". You may not see errors during development if you are deploying to your development machine.
As already mentioned in the answer by robertc, Chrome blocks certain functionality, like the geo location with local files. An easier alternative to setting up an own web server would be to just start Chrome with the parameter --allow-file-access-from-files. Then you can use the geo location, provided you didn't turn it off in your settings.
The easiest way is to click on the area left to the address bar and change location settings there. It allows to set location options even for file:///
Make sure it's not blocked at your settings
http://www.howtogeek.com/howto/16404/how-to-disable-the-new-geolocation-feature-in-google-chrome/
if you're hosting behind a server, and still facing issues:
try changing localhost to 127.0.0.1 e.g. http://localhost:8080/ to http://127.0.0.1:8080/
The issue I was facing was that I was serving a site using apache tomcat within an eclipse IDE (eclipse luna).
For my sanity check I was using Remy Sharp's demo:
https://github.com/remy/html5demos/blob/eae156ca2e35efbc648c381222fac20d821df494/demos/geo.html
and was getting the error after making minor tweaks to the error function despite hosting the code on the server (was only working on firefox and failing on chrome and safari):
"User denied Geolocation"
I made the following change to get more detailed error message:
function error(msg) {
var s = document.querySelector('#status');
msg = msg.message ? msg.message : msg; //add this line
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
// console.log(arguments);
}
failing on internet explorer behind virtualbox IE10 on http://10.0.2.2:8080 :
"The current location cannot be determined"
For an easy workaround, just copy the HTML file to some cloud share, such as Dropbox, and use the shared link in your browser. Easy.
I too had this problem when i was trying out Gelocation API. I then started IIS express through visual studio and then accessed the page and It worked without any issue in all browsers.
Check Google Chrome setting and permit location access
Change your default location settings.
On your computer, open Chrome.
At the top right, click More Settings.
Under "Privacy and security," click Site settings.
Click Location.
Turn Ask before accessing on or off.
After I changed those settings, Geolocation worked for me.
today i realize that some pages can locate me (im using a laptop with no gps built-in) using google chrome with a an very impresive exactitude, i know that using my IP you can locate me, but not with such presision. Now in google maps you will see a button on top of the yellow men (street view) who locates you using google chrome.
How does this work? There is an API to use that?
It's also possible with the actual HTML 5 Geolocation functions (only if your browser supports):
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
alert("Not Supported!");
}
function success(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
}
function error(msg) {
console.log(typeof msg == 'string' ? msg : "error");
}
var watchId = navigator.geolocation.watchPosition(function(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
});
navigator.geolocation.clearWatch(watchId);
Greetings,
Sascha
Check out the help page
The local network information used by Google Location Services to estimate your location includes information about visible WiFi access points, including their signal strength; information about your local router; your computer's IP address. The accuracy and coverage of Google Location Services will vary by location.
Here is a link to the Firefox code that allows you to access the Google Location Service:
http://mxr.mozilla.org/mozilla1.9.1/source/dom/src/geolocation/NetworkGeolocationProvider.js
Enjoy!