简体   繁体   中英

Kivy - Map options (google maps, etc)

diving further into kivy, i began to wonder what map options were available (either google maps or something like open street maps). What i found so far:

KivyMaps link So far the most usefull Module i found. It is supposed to work on mac, windows, android and iOS (experimental), BUT: i don't find the docs anywhere! I googled a lot, still i have not a clue how to use kivyMaps

Kivy Mapview link Available trough garden. Good docs, but they say it works only on android. For me, it does work on Kivy + Mac, at least displaying and moving the map. Setting coordinates and changing them does not.

So i guess my question is: What do you use? Are there other options available that i missed? Where are the KivyMaps docs (can somebody provide examples?)

For Kivy desktop applications you have another option for maps. You can use CEF Python to embed a web browser in your Kivy App. You can direct this browser to an HTML file that loads web based maps.

In order to use CEF Python, you'll have to install the module cefpython3. I'm pretty sure you can install this using:

kivy -m pip install cefpython3

otherwise, you can use a traditional pip install and move the module into a location where kivy can access it.

From this sample code, I made the following example by changing the start_url of the web browser like:

start_url="file://"+GetApplicationPath("testMaps.html")

Where testMaps.html is an HTML file with this Google Maps's sample code (the HTML + JavaScript version).

The Kivy code that I'm running is long and kind of complicated because CEF Python takes a lot of configuring... I probably don't need all the code that's in there, but I haven't tried slimming it down yet.

Here's the code! (You'll have to download it)

Yeah... pretty beefy. The HTML file will have to be in the same directory as the above code for it to work properly. Also, I put this together on a Mac, and some things might be different on Windows and Linux. Although the sample code I started with was written for Linux, so it could be that just the Windows folks will run into trouble.

If you've gotten the code to run and you're wondering what the forward and back buttons are for; that's just legacy from the example code I used as a base, and has nothing to do with the map.

Last note: I used Google Maps for this example, but with this method you could use any web based mapping utility.

There is also Kivy-GMaps , but according to them, it also only works on Android.

They provide some usage examples on the README.md.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM