kivy-garden / mapview

Mapview is a Kivy widget for displaying interactive maps.
https://kivy-garden.github.io/mapview/
MIT License
88 stars 29 forks source link

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #29

Closed asm201 closed 4 years ago

asm201 commented 4 years ago

I was trying to see the exemples documents but i receive this error:

Traceback (most recent call last):
   File "C:/Users/André/AppData/Local/Programs/Python/Python37/Lib/site-packages/kivy/garden/garden.mapview/examples/clustered_geojson.py", line 16, in <module>
     layer = GeoJsonMapLayer(source=source)
   File "C:\Users\André\AppData\Local\Programs\Python\Python37\Lib\site-packages\kivy\garden\garden.mapview\mapview\geojson.py", line 198, in __init__
     super(GeoJsonMapLayer, self).__init__(**kwargs)
   File "C:\Users\André\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 350, in __init__
     super(Widget, self).__init__(**kwargs)
   File "kivy\_event.pyx", line 262, in kivy._event.EventDispatcher.__init__
   File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__
   File "kivy\properties.pyx", line 544, in kivy.properties.Property.set
   File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
   File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
   File "C:\Users\André\AppData\Local\Programs\Python\Python37\Lib\site-packages\kivy\garden\garden.mapview\mapview\geojson.py", line 299, in on_source
     geojson = json.load(fd)
   File "C:\Users\André\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 296, in load
     parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
   File "C:\Users\André\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 348, in loads
     return _default_decoder.decode(s)
   File "C:\Users\André\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
   File "C:\Users\André\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 355, in raw_decode
     raise JSONDecodeError("Expecting value", s, err.value) from None
 json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

the code i was trying to run was this one:

from kivy.base import runTouchApp
import sys

if __name__ == '__main__' and __package__ is None:
    from os import path
    sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

from mapview import MapView, MapMarker
from mapview.geojson import GeoJsonMapLayer
from mapview.utils import haversine, get_zoom_for_radius

if len(sys.argv) > 1:
    source = sys.argv[1]
else:
    source = "https://storage.googleapis.com/maps-devrel/google.json"

options = {}
layer = GeoJsonMapLayer(source=source)

if layer.geojson:
    # try to auto center the map on the source
    lon, lat = layer.center
    options["lon"] = lon
    options["lat"] = lat
    min_lon, max_lon, min_lat, max_lat = layer.bounds
    radius = haversine(min_lon, min_lat, max_lon, max_lat)
    zoom = get_zoom_for_radius(radius, lat)
    options["zoom"] = zoom

view = MapView(**options)
view.add_layer(layer)

if layer.geojson:
    # create marker if they exists
    count = 0

    def create_marker(feature):
        global count
        geometry = feature["geometry"]
        if geometry["type"] != "Point":
            return
        lon, lat = geometry["coordinates"]
        marker = MapMarker(lon=lon, lat=lat)
        view.add_marker(marker)
        count += 1

    layer.traverse_feature(create_marker)
    if count:
        print("Loaded {} markers".format(count))

runTouchApp(view)
AndreMiras commented 4 years ago

Hi @asm201, thanks for the bug report! Ideally you should make a more minimalist example. More specifically I'd like you to make this part more clear so we don't have to guess what you passed in your sys.argv:

if len(sys.argv) > 1:
    source = sys.argv[1]
else:
    source = "https://storage.googleapis.com/maps-devrel/google.json"

Also since this is already crashing on this line:

layer = GeoJsonMapLayer(source=source)

Please cut the rest to provide the most minimalist and deterministic example so we can help debugging. Deterministic would also mean not relying on a remote location content that could change any time, hence please share (attach) the actual JSON file content you've tried with rather than the potential URL of it (https://storage.googleapis.com/maps-devrel/google.json). I hope that makes sense

asm201 commented 4 years ago

sorry i forgot to mention that this code is from exemple folder that comes with the garden.mapview, i also don't know what passed in sys.argv

AndreMiras commented 4 years ago

Clear thank you. This repo needs some love anyway. I'll try to look over the weekend

AndreMiras commented 4 years ago

After all the migration to the new repo, I could eventually play with it. And I found/fixed an issue d62fd928b3c84f5c916279bef14e07151da5e8c2, but not the one you reported. So to follow up on your issue, it sounds as if the json you were trying to use was corrupted. So what I suspect is probably your IP is getting a capacha or something on this file. If the issue is still present on your side I'll recommend you to try to access that file and see if the content is indeed a json. And if it is and you still have the issue, we can go through a more deep debugging session together Edit: Before you try again, you need to completely remove the old mapview you had and install thew new one using pip install mapview

asm201 commented 4 years ago

Strange, i tried to run again the aplication and now i receive a new error not releated to sys.argv:

File "C:\Users\André\AppData\Local\Programs\Python\Python37\Lib\site-packages\kivy\garden\garden.mapview\mapview\geojson.py", line 289, in on_geojson
     self.canvas_line.clear()
 AttributeError: 'GeoJsonMapLayer' object has no attribute 'canvas_line'
AndreMiras commented 4 years ago

Yes you're using an old version like I said. So uninstall it from garden and install it with pip

garden uninstall mapview

Then install the new version with pip:

pip install --user --upgrade mapview==1.0.4

For support question, you can use the support channel on Discord

asm201 commented 4 years ago

sorry i'm having this same problem:

File "C:\Users\André\AppData\Local\Programs\Python\Python37\Lib\site-packages\kivy\garden\garden.mapview\mapview\geojson.py", line 289, in on_geojson
     self.canvas_line.clear()
 AttributeError: 'GeoJsonMapLayer' object has no attribute 'canvas_line'

where i can find the link to the Discord server

AndreMiras commented 4 years ago

Yes and you're also up to date, why don't you uninstall this garden and use the one from pypi? https://github.com/kivy/kivy#support

asm201 commented 4 years ago

thank you, and i already have done that. i used the commands you passed

AndreMiras commented 4 years ago

Yes but your stack trace clearly shows the old garden module so it means it's taking over. Please share the command and output of your attempt to remove it via garden uninstall mapview. Ping me on Discord as it's more suitable to support