These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:12 pm Advanced search

HTML5 Geolocation issue

If you are stuck or have questions regarding HTML or other Web technologies, ask your questions here. No question too dumb!

HTML5 Geolocation issue

Postby Gemma Reinicke » Wed Jul 25, 2012 1:41 pm

Hi.

I wrote this script

Code: Select all
<!DOCTYPE html><html><head>
<script>
    function getCurrentPosition() {
        // Try W3C Geolocation (Preferred)
        if (window.blackberry && blackberry.location.GPSSupported) {
            blackberry.location.setAidMode(2);
            blackberry.location.refreshLocation();
            document.location = 'index.php?lat=' + blackberry.location.latitude + '&lon=' + blackberry.location.longitude + '&adr=Standort+Mobiltelefon&radius=6';
        } else {
            if (navigator.geolocation) {
                browserSupportFlag = true;
                navigator.geolocation.getCurrentPosition(function (position) {
                    document.location = 'index.php?lat=' + position.coords.latitude + '&lon=' + position.coords.longitude + '&adr=Standort+Mobiltelefon&radius=6';
                }, function () {
                    handleNoGeolocation(browserSupportFlag);
                }, {
                    enableHighAccuracy: true,
                    maximumAge: 0,
                    timeout: 30000
                });
                // Try Google Gears Geolocation
            } else if (google.gears) {
                browserSupportFlag = true;
                var geo = google.gears.factory.create('beta.geolocation');
                geo.getCurrentPosition(function (position) {
                    document.location = 'index.php?lat=' + position.latitude + '&lon=' + position.longitude + '&adr=Standort+Mobiltelefon&radius=6';
                }, function () {
                    handleNoGeoLocation(browserSupportFlag);
                });
                // Browser doesn't support Geolocation
            } else {
                browserSupportFlag = false;
                handleNoGeolocation(browserSupportFlag);
            }
            if (browserSupportFlag) {
                watchId = navigator.geolocation.watchPosition(function (position) {
                    if (position.coords.accuracy <= 50) {
                        document.location = 'index.php?lat=' + position.coords.latitude + '&lon=' + position.coords.longitude + '&adr=Standort+Mobiltelefon&radius=6';
                    }
                }, function () {
                    handleNoGeolocation(browserSupportFlag);
                }, {
                    enableHighAccuracy: true,
                    maximumAge: 0,
                    timeout: 30000
                });
            }
        }
    }

    function BlackberrylocationCB() {
        document.location = 'index.php?lat=' + blackberry.location.latitude + '&lon=' + blackberry.location.longitude + '&adr=Standort+Mobiltelefon&radius=6';
    }

    function handleNoGeolocation(errorFlag) {
        document.location = 'index.php?lat=0&lon=0&adr=Standort+Mobiltelefon&radius=6';
    }
</script>
</head><body onLoad="getCurrentPosition();"></body></html>


Which is to forward lat and lon from several gps-sources to index.php as parameters you can fetch with $_GET in PHP.

If handleNoGeolocation is executed, lat=0 & lon=0 is set. Using opera, chrome, ie, I get correct coordinates. Using my android phone's browser or firefox I get lat=0 & lon=0. Even though the apb and ff ask whether position should be transmitted, and a point inside a circle is flashing in android, they don't seem to pass this data.

Is this a android / ff issue you can resolve with adapting this code? If so, how?
User avatar
Gemma Reinicke
<h6>
 
Posts: 1
Joined: Wed Jul 25, 2012 1:20 pm

Re: HTML5 Geolocation issue

Postby zcorpan » Thu Aug 16, 2012 7:52 am

You say "// Try W3C Geolocation (Preferred)" but then go on and try blackberry.location.GPSSupported first and navigator.geolocation second. Shouldn't it be the other way around?

That probably doesn't fix the issue, though. I guess the error callback is invoked. Maybe it times out? What happens if you remove the settings argument?
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to Help & Advice

Who is online

Users browsing this forum: No registered users and 1 guest