osmdroid - Import KML file of Areas - android

I wanna show areas on the map, each area has its own .kml file, how can I import them to osmdroid and show them automatically ?

You should have one kml file for all areas not one file per area.
But you can OSMBonusPack to load kml file in osmdroid map.
Also you can see this example.

To complement the answer from Seyyed, and assuming these files are not too big:
You can have one kml file for each area, and then build a simple "global" file, referencing all these area files with a "NetworkLink" (look at to KML Reference if needed for the syntax).

Related

How to create my own Vector Drawble? (Android)

I need to use an icon of a contract on my app.
Usually, I'd create a new Vector Asset and lookup for an icon that might do the job.
Unfortunately, this time I couldn't find anything similar to my needs, so I want to create one!
I tried reading about the issue here but it wasn't really helpful.
can someone tell me how to do that and what is that pathData?
Thanks!
You can create vector assets from SVG sources. If you want to create your own icon, you should probably use a graphics program that can export drawings as SVG. Inkscape for example is free and available for a lot of platforms.
When you have the SVG file, in AndroidStudio select File -> New -> Vector Asset. In the upcoming dialog, select Asset Type 'Local file' and then pick/enter the path to your SVG.
You can download from the web / create by photoshop your own SVG files , once you have .svg file you can add it to your project by right click on app > new > Vector Asset > Local file (SVG,PSD) and use it as you normally use android:src="#drawable/ic_my_icon"
now a pathData is A path that represents the outline of a shape which can be filled or stroked. A path can also be used as a clipping path, to describe animation, or position text.
But for me what really did the job was just playing with the numbers of it and see the reaction of the actual path, what do i mean ?
Check out ShapeShifter and watch this video , drag some .svg files from the web and start playing with it , I'm sure you will get the idea .

Failed to decode image. The provided image must be a Bitmap. - With PNG

I'm currently following a tutorial for an Uber clone and at this part
carMarker = mMap.addMarker(new MarkerOptions()
.position(currentPosition)
.flat(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.car)));
where we add the marker of the car into the current position for moving it from point to point, the app crashes and the debbuger says "Failed to decode image. The provided image must be a Bitmap".
The 'car' image is a png file inside the drawable folder, I've tryied some solutions as Custom marker in google maps in android with vector asset icon and others, but none actually solved.
Can anyone help here? For me it looks like it's all fine: the image is a png file, it's on the drawable folder, why is it not considering as a bitmap?
I found the answer. When pasting the car file inside the drawable folder, Android Studio gives options of drawable source folders to save it, the default option is the "drawable-v24" folder aaand the R.drawable takes the image inside the "drawable" folder. So it needs to change from "drawable-v24" to "drawable" when pasting the image and that will work.
Try This.
Convert PNG images into jpg format and make sure the resolution of the image is not too high. I had the same experience and then I used jpg with low-resolution images.

how do you use svg in drawable folder?

i am creating a bottom navigation bar for a android app following this guide
however, when using svg in android:icon and building it, it shows a error
Error: The file name must end with .xml or .png
i found out that i needed to move the svg to the assets folder. but if i move it, i can't use the svg... any help is much appreciated, thank you
The answer above gives a link to convert pictures from SVG to XML, but this tool is not for free(only for one SVG file)
So why not to use ANDROID build-in tool?
The best way is to go to res-> drawable-> Vector Asset -> Local file (SVG, PSD) ->select your SVG file from the place you save it.
and you are done :)
Android uses vector drawables which are xml files rather than SVG's.
You will have to convert the SVG to a vector drawable. Many ways of doing it but a handy web tool is available here.
It won't do complex SVG's but copes with the majority.

Openstreetmap Overlay Osmdroid example

I am looking at the SampleWithTilesOverlayAndCustomTileSource example in the osmdroid pack and I am wondering where the overlay is coming from/what format the overlay openfietskaart-rcn is - is it Openlayers/a WMS service and how can I make my own custom overlay working for this example? Would it work with GeoServer? I was not able to find tutorials on this example and hope someone can give me a hint on how to create my own layer, based on a .kml file for example. Thanks!
this.mCustomTileSource = new XYTileSource("FietsRegionaal", null, 3, 18, 256, ".png",
"http://overlay.openstreetmap.nl/openfietskaart-rcn/");
example here:
http://code.google.com/p/osmdroid/source/browse/trunk/OpenStreetMapViewer/src/org/osmdroid/samples/SampleWithTilesOverlayAndCustomTileSource.java?r=829
The custom tile source doesn't specify a custom URL scheme, so you can assume it uses the default implementation - a folder structure of PNG files starting at the base URL above, followed by zoom/X/Y.png. The numbering matches Google Maps system. Each PNG is 256 pixels square. You can create a custom set of tiles using Mobile Atlas Creator (MOBAC), or I used a library called "mapnik" to convert KMLs to tiles. The tiles could also come from your sdcard.
Here's a good site to show how the tiles are numbered:
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
MOBAC:
http://mobac.sourceforge.net/
Mapnik:
http://mapnik.org/

Streetnames openstreetmaps more readable on Android

I've build an Android APP with offline map data using Openstreetmaps and OsmDroid. On a device with MDPI 320x480 pixels the map looks OK, but on a device with a HDPI screen with 480x800 pixels the street names are small and a little bit harder to read them. My map data till zoom level 18, the maximum I could download and use with Mapnik tile source, is loaded as a zip-file from the SD-Card. My local maps are from a defined region of Brussels (Belgium).
A screenshot of an MDPI device with 320x480 pixels:
A screenshot of an HDPI device with 480x800 pixels:
If you see these views in the app on the device the MDPI map is good readable, in the HDPI map the street names are smaller.
Is there a way to make the street names also more readable on the HDPI device, so the user haves the idea that he zooms one step further on the map? Because it's not possible to go to zoom-level 19, because there is no openstreetmaps data for it. So a little workaround solution with easy and small implementation time/work my be OK for me. Zooming is now done by swiping on the map. If you also need the code, let me know and I'll post it.
Thanks in advance.
Kr
Osmdroid works with tiles that are static PNG images. You can not change the tile images. If you want to have a better mapping solution try MapsForge. This app/library works with maps data and renders them dynamically. This way you have more control on rendering maps and you can customize its texts and fonts and colors.
In this answer I will explain a little bit how I changed the size of the street names.
In the jar file of MapsForge there is a xml-file included that will standard be used for rendering the map data. You can download this file also by checking out the source code from the server: http://mapsforge.googlecode.com or download the xml-file itself from here: http://mapsforge.googlecode.com/svn/trunk/mapsforge-render-theme/src/main/resources/osmarender/osmarender.xml. So, you have a basic to tweak your own render file. I tweeked it a little bit like this:
(snippet of the xml-file):
On the Wiki-page of the MapsForgeRenderThemeAPI page (on the site above) you can find how to tweak your own render file and what e, k, v attributes in the rule element means. As you can see there is a rule element with e="way", k="area", v="~|no|false" inside the no-tunnel way rule-element somewhere under the way rule-element. Every rule-element under this element haves
an e="way", k="highway" and v value equal to the openstreetmap parameters. As you login to the edit page on openstreetmap.org you can find out the kind of streets you want to tweak the names for.
Now I gonna tell how you can exactle the font-size you want for a specified type of street. As an example I will take the tertiary road element. Each kind of way rule-element contains some code like this:
<rule e="way" k="highway" v="tertiary">
<line stroke="#ffff90" stroke-width="1.5" />
<rule e="way" k="*" v="*" zoom-min="14">
<pathText k="name" font-style="bold" font-size="32" stroke="#ffff90" stroke-width="2.0" />
</rule>
</rule>
The line element specifies how the street will be displayed (color, width, black border, ...).
There is again a rule-element inside here containing a pathText element. This element specifies how the text will be displayed inside the stroke(color, width, font-size, ...). So, this is the element we need! In my example, as you can see, the font-size for the street names for a tertiary road will be displayed with a size of 32 pixels for a zoom-in-level of 14 or higher.
Now we want to use our own render theme xml file:
I've added my own render-xml file in the assets folder of my project. Than a t launch time, I copy the file to a location from where I can read it out when it is needed. In the activity where you handle your mapsforge map you only have to link to this file by implementing code like this (example):
File f = new File(Environment.getExternalStorageDirectory(), myRenderTheme.xml);
mapView.setRenderTheme(f);
Note that setRenderTheme(File) will throw a FileNotFoundException.
So, this is all for changing the street names with mapsforge. You can render you're whole map as you want!
Thanks to the MapsForge development community.
Have fun!
Kr

Categories

Resources