How to draw route on map with KMLParser - iphone

I am parsing a kml file using KMLParser in my application. When i open the kml file in google map it shows me the route with annotations & overlay's. My query is
1) Is it possible to get the route data from kml to draw the route on map
2) If not how can i achieve route drawing from kml file
Any suggestion or hint will be helpful.

I am not sure if you can get the route data from the KML-file using KMLParser, as I'm not sure what features that parser provides. An alternative to using KMLParser would be to simply parse the KML-file yourself, using for example KissXML och GDataXML. If you only need the route information from the KML-file, using a plain XML-parser might be simpler.
You need to parse the data and then translate it into something you can draw on the map, like CLLocationCoordinate2D. Once you have your data as an array of CLLocationCoordinate2D-coordinates, you can follow this tutorial for learning how to draw a line on a map: http://www.raywenderlich.com/30001/overlay-images-and-overlay-views-with-mapkit-tutorial Specifically the section "I Walk The Line – MKPolyline".
Good luck!

Related

Extrapolate Coordinates form Leaflet map

I'm planning a climbing trip and I wanted to retrieve the climbing locations from a leaflet map.
I thought I could use chromedriver and selenium to get the information I wanted but I'm having difficulty scanning through all markers since I can't understand where all the informations are stored.
Could someone guide me through how I could get the information? (also without using selenium)
The map in question is: https://www.climbingsardinia.com/topos/maps/
Thank you in advance.
in that page you will see a global variable called cttm_markers, it contains all markers informations and relative coordinates.
For example, cttm_markers[0][[0].additionalData.title evaluates "M.te Arci – Trebina Longa".Further, cttm_markers[0][[0]._latlng is an object {lat,lng} that contains coordinates.
Try to open console and paste this: JSON.stringify(cttm_markers[0].map(c=>({title:c.additionalData.title,latlng:c._latlng}))), it will print a json.
One way to do it is to get some information on one of the markers and use this to search the request reponses made by the page (you can do this in the debug tools, usually opened with F12). One of the markers for example reveals the location "Grighini". The base request redirects to (in my case) https://www.climbingsardinia.com/topos/maps/?doing_wp_cron=1651158093.0027918815612792968750
Searching the response, reveals that in line 1908 there's the string "Grighini". This line contains a serialized JSON array, containing the markers.

Convert mbgl-offline db to mbtiles

I'm trying to implement mapbox offline in my flutter application... until now I'm using the repository https://github.com/mapbox/mapbox-gl-native to get the map but this map comes in format *.db which is a SQLite format.
Now if I want to use that map (in format .db) in flutter I found the package https://github.com/tobrun/flutter-mapbox-gl where it has an instructions for loading the map (.db) ...
Now, that library is so basic .. I can't do more things like put markers or anything else.. that's why I'm trying to use the other library which is more common in fluter and is called 'flutter_map' and it has a way to load offline maps but the problem here is that I need '{x}{y}{z}.png' that's an image format.
Finally my question is: How can I pass from my map (.db) to that format ({x}{y}{z}.png) ??? or maybe ... how to convert (.db) to (*.mbtiles) ?? cause the last one is more common.
Thanks again!
Mapbox offers the Raster Tiles API which will serve map tiles in ({x}{y}{z}.png) format. https://docs.mapbox.com/api/maps/#raster-tiles These images will be satellite imagery though.
Mapbox also offers the Vector Tiles API which serves map tiles in .mvt format.
https://docs.mapbox.com/api/maps/#vector-tiles
Conversion to .mbtiles
You can convert .mvt tiles to geoJSON using this converter.
Use Mapbox Tippecanoe to convert from geoJSON to .mbtiles

Parial Zip Code Search autocomplete with Bing Map

I am using Bing Map to display Pushpins based on addresses I have. But sometimes I may get only Partial Zip Codes in addresses which lead to weird display of map. So I have come up with idea that I will use first matching zip for partial zip code.
e.g. if partial zip code is 640 then retrieve the zip codes those starts with 640 and let say I got 6402342, 6408678, 640893. Then render pushpin for co-ordinates of first matching zip code that is 6402342.
So my question is that is there any Bing Map API which could give me the list of matching zip codes as if it gives in autocomplete search box or else is there any better approach to handle partial zip codes on Bing Map.
If you have the rest of the address, try reverse geocoding it's coordinates. It will often return a fairly accurate postal code which would be more accurate than choosing the first zip code from a list. Reverse geocoding can be done using either the REST service: https://msdn.microsoft.com/en-us/library/ff701710.aspx Or by using the search module in the Bing Maps web control:
https://msdn.microsoft.com/en-us/library/mt712821.aspx
http://www.bing.com/api/maps/sdk/mapcontrol/isdk#searchByPoint+JS
If you really want a list of zip codes, you would be best off to download a list from a site and store them. GeoNames has a good collection of Zip codes. Here is a link to the zip file for the US: http://download.geonames.org/export/dump/US.zip
You can find downloads for other countries here: http://download.geonames.org/export/dump/

Getting routes on openstreetmaps using OSRM

I've been trying to get a list of co-ordinates in a route from point A to B using OSRM with the following request:
GET http://router.project-osrm.org/viaroute?hl=en&loc=47.064970,15.458470&loc=47.071100,15.476760
However, on opening the url, i find the 'via_points' tag containing only two co-ordinates. Surely, that can't be the entire route? Anything I'm missing here? Is there any other way of generating the list of route co-ordinates with OSRM? Thanks
The route is contained in the route_geometry object. It is an encoded polyline. If you don't want to uncompress it yourself you can disable compression via compression=false:
http://router.project-osrm.org/viaroute?compression=false&hl=en&loc=47.064970,15.458470&loc=47.071100,15.476760
Not sure what the via_points contains. OSRM's documentation seems to be outdated. Maybe they are just your start and end points snapped to the nearest road or something similar.

Getting distance between 2 markers

I would like to get the distance between 2 markers but not as a direct line, more as a real path like it goes in this plugin -
https://github.com/perliedman/leaflet-routing-machine
I didn't find anything about using this plugin in the directive: angular-leaflet-directive,
if someone can guide how to make it done, it would be very appreciated.
thanks!
I am not sure if you specifically want to use leaflet routing machine to get distances... but if you do, maybe this info can get you started:
Set up a route on your map based on this example by the leaflet routing machine author:
https://www.liedman.net/leaflet-routing-machine/tutorials/interaction/
If you look at that example, there is an array called routes. Each route has some basic statistics associated with it, generated by OSRM. You can pull them by calling for example:
routes[0].summary.totalDistance
or
routes[0].summary.totalTime
Then you can do whatever you want with them. If you dig through the code on GitHub you can see more about how the data are moved around within the plugin and why the array is arranged that way:
https://unpkg.com/leaflet-routing-machine#3.2.12/dist/leaflet-routing-machine.js