How to get the shape of a lake with the HERE-API - android

I'm building a rowing-related Android app with the here-api and would like to compute the (closest) distance to the shoreline to warn a rower if he is too close (which is not allowed on some lakes). I found a way to get the are for cities or postalcode but not for a location (with "LocationType": "lake").
Here obviously has this data, but is there a way to get it from them?

Sorry for the confusion.
HERE-API supports that shape data.
please see below documents.
https://developer.here.com/documentation/platform-data/topics/resource-layers.html
Below request will list layers.
https://pde.api.here.com/1/doc/layers.html?app_id={{app_id}}&app_code={{app_code}}
And there is some layers you are interested in
especially Layers CARTO_POLY_DO1 to CARTO_POLY_DO5 have polygon shape data.
Also below request list the detail information of the layer.
https://pde.api.here.com/1/doc/layer.html?layer=CARTO_POLY_DO3&app_id={{app_id}}&app_code={{app_code}}
I hope this help!

Related

OSMDroid Points of interest using multiple facilities

I am using OSMDroid with its bonus pack to display a map and get point of interest near a location, but I can't find a way to get POI of different type in once.
As indicated in the documentation I am using the function getPOICloseTo() but it doesn't seem to handle a null facility to return all types of POI.
val poiProvider = NominatimPOIProvider("OSMBonusPackTutoUserAgent")
val pois = poiProvider.getPOICloseTo( GeoPoint( geoPoint ), "cinema", 10, 0.1 )
If there is a way to avoid making one call per POI type I would like to know it !
Thanks in advance, have a nice day
I don't think you can do that with Nominatim service. You can dig in Nominatim API doc (having a look at Special Phrases).
Alternative: move to OverpassAPIProvider. A little bit complex, but super-powerful. I'm quite sure it will match your need.

How to highlight a LineString (or Polygon) in Mapbox Android from a GeoJSON or the mapboxId

I am trying to highlight a feature on a map using Mapbox Android SDK. First, the map is loaded in the app using custom styles from a vector tiles server.
To highlight the feature, the data is received from a server with the coordinates and feature data stored in the database. The android app receives a GeoJSON like this:
{
…
"geometry":{
[enter image description here][1]"type":"LineString",
"coordinates":[
[-6.280378997325897,36.52107960787673],[-6.280381679534912,36.52104619723205],
[-6.280373632907867,36.52102787525949]
]
},
"mapboxId":487
…
}
I use the geometry type to know the type of object and then create a feature of the same type from the geometry itself.
when (current.getGeometryType()) {
POINT -> …
LINE_STRING -> marker.geometry = LineString.fromJson(current.getGeometry())
…
}
Then I add the Source and Layer with some properties.
style.apply {
addSource(
GeoJsonSource(
SOURCE_ID3_RED_BORDER,
FeatureCollection.fromFeatures(marker)
)
)
addLayer(
LineLayer(
LAYER_ID3_RED_BORDER,
SOURCE_ID3_RED_BORDER
)
.withProperties(
PropertyFactory.lineGapWidth(5f),
PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND),
PropertyFactory.lineCap(Property.LINE_CAP_ROUND),
PropertyFactory.lineWidth(2f),
PropertyFactory.lineColor(Color.RED)
)
)
}
But my LineString does not exactly fit with the LineString data received from the server, probably due to generalization of the vector tiles, since we receive
see image
The result is not what I expected, I would like the red line to fit exactly with the green one. I don’t know why the lines don’t fit.
Is there a way to achieve this? It seems to be similar to the "Select Building" example (https://docs.mapbox.com/android/maps/examples/select-a-building/) but the feature to be highlighted is not driven by the selection of the user, but from a know feature data coming from a server when loading the map view.
For some parts of it, like the curve, you do not have enough coordinates to represent the curve. For the straight parts, there appears to be the same problem. When you look at the part below the yellow region, the red lines are perfectly aligned with the green.
In this parts you have sufficient coordinates. In the rest you do not.

How to filter markers in Mapbox Sdk

I'm creating an Android app using MapBox. I've already set up a simple map functionality with markers sourced from .json file. Next step is filtering the markers on the map, just like in this gl-js example here:
https://docs.mapbox.com/mapbox-gl-js/example/filter-markers/
I can't find any sdk examples anywhere, and since this is my first app I really can't figure it out on my own. Any help will be appreciated.
You can check out this example https://docs.mapbox.com/android/maps/examples/multiple-expressions-temperature-change/ that features two layers that fetch a min or max temperature from the data source and display it.
The filtering part is done here:
// Only display Maximum Temperature in this layer
maxTempLayer.setFilter(eq(get("element"), literal("All-Time Maximum Temperature")));
loadedMapStyle.addLayer(maxTempLayer);
Filters accept expressions as arguments, and here Expression.eq is used to compare "element" from the GeoJSON data source (referenced with the Expression.get) with the "All-Time Maximum Temperature" value. If it resolves to true, the feature is going to be displayed, otherwise, it's going to be hidden.

Displaying KML Layers on Maps at Native Android apps Best Practice

I have big KML file to a native Android application, please check the following details and give an advice.
KML file details:
size: 1.7 MB
total number of kml file elements: 500 elements
total number of polygon: 1000 polygon
Android app details:
the above details will be viewed in Fragment
I used the following support library to implement this screen
compile 'com.google.maps.android:android-maps-utils:0.4+'
some caluctations are done on loading the screens(like distance calculations)
Issue:
Take a lot of time to load the map and kml layer about 8 sec
create KMLLayer instance
What is the best practice to implement the above details with good performance?
please advise.
Best practice is doing long time operation in background (for example, on separate thread) and split complex tasks into small parts. So you can:
1) create and start load KML layer as soon as possible (e.g. on app create) and than just show it;
2) instead of one kml file with 500 elements and 1000 polygons, use 50 kml files with 10 elements and 100 polygons and load to layer only necessary files (for example you can split it by area location, or by semantic information, or by something else criteria);
3) combine 1 and 2 points;
4) precisely for google maps it's possible to create tiles with information from kml files and use TileProvider.
Since there's no actual answer, I'll post my own solution.
I've done mainly two things to optimize this.
Instead of using Google maps utils built-in method addLayerToMap - I've used my own custom implementation. I've done so, because parsing kml is relatively fast(in my case - ~5-10 seconds) and it can be done in background thread. Adding all the points to the map, however, takes more than 10 seconds, and must be done on UI thread. Basically, I've used KmlLayer class as a base, and parsed kml file by myself into polygonOptions and all other things I need.
Calculate which items are visible and which are not. Firstly, I filter which items are outside screen bounds. After that, I calculate each item's size(in pixels, no meters) - if item is smaller than threshold - item is also filtered out.
With these hacks applied, instead of freezing app for 15 seconds, user can freely navigate through map, and when he stops, after several seconds information will be displayed.
I just make some updates on the screen behavior to get good performance and good user experience by the following steps:
Divide the KML File to 65 files (the main areas on the map, for example, Zone A11 is located in one KML file and it contains all its details like Zone A11-1, Zone A11-2 and Zone A11-4 ...) and this division is done to be suitable the screen experience (for example user requirements)
on the first load, I am loading only the markers for all KMLs centers and that is not affecting the performance
When user click on the marker, I am loading the KML file for this area and zoom this area
When user zoom out, I am removing this layer from the map and load marker
When user moves the map I am calculating the nearest marker and load its KML layer
Note: preparing files on app launching will not provide better performance because the bad performance comes from adding the KML layer to the google map
Note2: using custom implementation for parsing and adding to Google map take a lot of time or need a lot of unit testing, and I think it's not recommended solution because it's better to leave this solution to be on Google Map utils build-in method (it's customized and always up to date)
I'd suggest you to make sure that you are constructing the KmlLayer on a background thread and addLayerToMap() has to be done on the main thread though like this
GlobalScope.launch {
val stringUrl: String = "https://saltwx.com/bath/SW_bath6.kml"
val inputStream: InputStream = URL(stringUrl).openStream()
val layer = KmlLayer(map,inputStream, applicationContext)
runOnUiThread {
try {
layer.addLayerToMap()
} catch (e: Exception) {
e.printStackTrace()
}
}}

Add a layer of paths on whole map

I use here-map sdk. I have db file with 16500 ! paths (coordinates of a point). I need to draw all paths on the map, when user activate function "show additional paths". But i think, if i try to fetch big number of path and add all poplilynes object on here map, it will take a huge amount of time.
Help to find the optimal solution.
I would filter your data based on the visible viewport and disable this functionality where it doesn't make much sense (continental or globe level).
So, let's assume you app shows the map on zoomlevel 16 or 17 (district level), you can retrieve the viewport as GeoBoundingBox from the Map instance (e.g. via mapView.getMap()) with getBoundingBox().
The GeoBoundingBox makes it easy for you now to check for collisions with your own objects, since it has several "contains()" methods.
So everything that collides with your viewport should be shown, everything else is ignored.
You can update whenever the map viewport changes with either listening for OnTransformListener in the Map class or register for the MapGesture events (get MapGesture via getMapGesture() and listen for zooming events via addOnGestureListener())
If the amount of data for filtering is still too big, you can also think about preparing your data for more efficient filtering, like partitioning (region based would be my first idea) so only a subset of your data needs to be filtered.
It seems that Custom Location Extension (https://developer.here.com/platform-extensions/documentation/custom-location/topics/what-is.html) can help with this case.
In short, it allows you to upload a custom data to the HERE backend and query it later.

Categories

Resources