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.
Related
I'me developing a game in AS3 AIR and I'me using Distriqt GameServices native extension.
The problem is that I can not sign in to Apple Game Center.
In the documentation, it's stated that: If Google Play Services aren’t available then you won’t be able to use the functionality in this extension.
And there's a code snippet:
var result:int = GoogleApiAvailability.instance.isGooglePlayServicesAvailable();
if (result != ConnectionResult.SUCCESS) {
if (GoogleApiAvailability.instance.isUserRecoverableError( result )) {
GoogleApiAvailability.instance.showErrorDialog( result );
} else {
trace( "Google Play Services aren't available on this device" );
}
} else {
trace( "Google Play Services are Available" );
//init here
}
That sounds odd to me because Google Play Services are not available on iOS, naturally.
I've tried to skip this step and initialize the service without checking GoogleApiAvailability. But I'm getting this message after a successful initialization and then calling signIn() method:
The requested operation could not be completed because local player has not been authenticated.
That sounds odd too, because this is the authentication method itself!!
I'm almost sure that my setup is correct. And the extension is working fine on Android.
GameServices ANE Version: 5.0.011
Any help is appreciated,
Thanks
Ah, actually that had nothing to do with the Distriqt GameServices, so sorry.
The message "The requested operation could not be completed because local player has not been authenticated." was coming from iOS meaning the Game Center is not activated on the device.
Switching on Game Center in the device (settings-> gamecenter) solved the issue.
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");
}
I am experimenting with azure mobile services and have implemented the authentication example here. This works on most devices ( iOs, IE9 and chrome on desktop, IE10 Surface RT, android ) but on a WP8 device ( a Nokia 920, to be precise ) it returns
"Cannot reach window opener. It may be on a different Internet Explorer zone"
after attempting to return from the authenication providers pop-up. This is mentioned briefly in the link above, but only wrt to connecting to the service from localhost. This is not the case here and other devices work fine. It does not seem to be a problem with any particular authentication provider - all ( facebook, google, twitter, windows connect ) return the same message. And as these other devices work, it seems unlikely that the service is mis-configured, but there could very well be something subtle that I'm missing.
The way I got the authentication to work is not to use Facebook JavaScript SDK, but another flow, described here https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/#step2
For handling the response when I get the redirect back from Facebook, I used the following code:
function handleLoginResponse() {
var frag = $.deparam.fragment();
if (frag.hasOwnProperty("access_token")) {
client.login("facebook", { access_token: frag.access_token }).then(
function () {
// do your thing when logged in
}, function (error) {
alert(error);
});
}
}
This code makes use of jQuery BBQ plugin, found here http://benalman.com/projects/jquery-bbq-plugin/.
This way I can get Facebook auth to work on WP8 and I'm able to pass the access token to Mobile Services login.
A slight problem is that now the access token sticks in my site URL, which I think is a problem if the user decides to share the URL, for example. I think I can get around this by e.g. putting the info in a cookie (or local storage) and then redirecting to the plain URL of my site.
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!