sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

geolocation demo getting javascript error on safari #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. using safari 5.1.7 on windows 7 or mac os/x 10 or safari on ios4 or ios5
2. go to http://www.brython.info/gallery/geoloc.html
3. click allow sharing of location

What is the expected output? What do you see instead?

Your position, along with latitude, longitude etc.
Instead, it only displays Your position and I get a javascript error:
undefined
TypeError: TypeError: TypeError: %f format : a number is required, not <class 
'NoneType'>
module '__main__'line 13...

Please use labels and text to provide additional information.

Original issue reported on code.google.com by francois...@gmail.com on 31 Dec 2012 at 3:53

GoogleCodeExporter commented 9 years ago
Same error in Chrome. It seems to be happening when it can't detect one of the 
attributes, and so crashes when it calls %f on NoneType.

Little rewrite to make it look nicer, and it works in chrome and on android 
like this:

geo = win.navigator.geolocation

def navi(pos):

    xyz  = pos.coords

    data = {
            'lat':xyz.latitude,
            'lon':xyz.longitude,
            'acc':xyz.accuracy,
            'timestamp': pos.timestamp,
            'alt':xyz.altitude,
            'alt_acc':xyz.altitudeAccuracy,
            'heading':xyz.heading,
            'speed':xyz.speed
           }

    ul = UL()
    for key in data.keys():
        try:
            string = key + ': ' + str(float(data[key]))
        except ValueError:
            string = key + ': Could not detect'

        ul <= LI(string)

    doc <= H3("Your position")

    doc <= ul

def nonavi(error):
    log(error)

if geo:
    geo.getCurrentPosition(navi, nonavi)
else:
    alert('geolocation not supported')

Cheers
-kelly

Original comment by Kelly.R...@gmail.com on 6 Jan 2013 at 9:43

GoogleCodeExporter commented 9 years ago
committed Kelly's fix

Original comment by francois...@gmail.com on 16 Jan 2013 at 7:08