drawing line between two coordinates on google map - iphone

I am having two coordinate points on Google map. I calculated the distance between that points. But I want to draw a straight line between them. Please help me to draw.

You have to use google direction api for that follow the Direction API Link .
Make request using NSURLConnection with direction api url and pass required addresses from it it and catch its response.
From that you will get json or xml formatted response, which contains paths in the form of polyline encoded string .
Then parse it and retrieve polyline encoded string.
You have to simply decode it it then you will get all points of your path and pass it to viewForOverlay method of MKMapViewDelegate which will draw the path.
For more information follow my question Stackoveflow question link .
If you have any more quires let me know. Hope this will help you....:)

Related

Get buildings polygons points from mapbox with fetch API only

I try to get the buildings geometry coordinates polygons from features, but i cant seem to find a way for this to work without the javascript method queryRenderedFeatures or SourceFeatures.
This question Getting building information from mapbox api uses the javascript method, but i want something to work with a link, that i can fetch a json from.
I have managed to come close with something like this:
https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/tilequery/27.598505,47.162098.json?radius=30&layers=road,poi_label,building,geometry&access_token=ACCESS_TOKEN_HERE.
But this has a major flaw:
It only returns geometry as a point:
{"type":"FeatureCollection","features":[{"type":"Feature","id":235028771,"geometry":{"type":"Point","coordinates":[27.598497434198464,47.16209573500234],"type":"building"...}}
You can observe that it returns a point even though it is a building.
Is there a way to do this?
The queryRenderedFeatures method DOES return a polygon. Somehow the information reaches the Map object that i query but how can i fetch through an api that info?
What you're trying to do is not possible. Mapbox doesn't provide complete polygon datasets. At best, there are ways of retrieving polygons from vector tilesets (such as query-remote-tiles, which does something similar to TileQuery). But these will only retrieve the part of the polygon within a given vector tile, which may not be what you want. (queryRenderedFeatures has the same issue).

How do I use the snap to road function using OSRM?

I am currently working with OSRM and used some GPS data for testing which i generated using googles Interactive Polyline Encoder Utility
https://developers.google.com/maps/documentation/utilities/polylineutility
The concept im going for is that a car is driving along a street sending every 20 seconds its GPS location. I want to display the path and the kilometers it drove at the end of its trip.
I set up a Client in C# performing a GET request with the match algorithm to communicate with the api on the open demoserver backend http://router.project-osrm.org
The problem is that i cannot use the match algorithm because it only takes two GPS points instead of a polyline consisting of several GPS locations. To me this does not make sense.
I tried this and it worked not that bad but it lost track and somehow ended at a point i didn't define, probably because of the quite long distance between the two points but i need it to work for more than two though:
here's the picture of it where it went wrong
http://router.project-osrm.org/match/v1/driving/13.682632,47.393753;13.6849281,47.3935649?overview=full&radiuses=49;49
I also found some decent blogs and websites telling me that I should use the OSRM matching algorithm as a Snap to road tool. One of them is this one: https://www.jamesrcroft.com/2015/06/snapping-gps-tracks-to-roads/
I also tried the route method which according to the OSRM wiki finds the fastest route between coordinates in the supplied order. Thats not exactly what I want. At least it could take a polyline of GPS locations but it was always extremely inacurate and faulty.
This is the GET Request for the method route I used:
Pic of how it looked before OSRM, it is slightly inacurate so i want it snapped to the road:
string polyline = #"kz~dHclrbBbAfAn#iBb#{Cf#aBXkA_#s#m#i#_A}#c#c#Fu#Tq#ZWXT";
string.Format("http://router.project-osrm.org/route/v1/driving/polyline({0})?overview=full", polyline);
As response i got this polyline in the attribute geometry:
mz~dHalrbB`#b#XZFFFHBK#CBI#E\\uA\\mA?[?SH[Ru#Nm#XkAFOg#a#m#g#AA}#_Ac#c#IIPk#Tq#Nc#?A??
This is what i got when I decoded it through the google polyline encoder: a complete mess..
Could someone explain what I am doing wrong? Thank you in advance!
I am sure the problem is that you do not send the timestamp of each geolocation in unix time.
Take a look at the official documentation: http://project-osrm.org/docs/v5.5.1/api/#match-service
This is how your request should look like:
http://router.project-osrm.org/match/v1/driving/13.682632,47.393753;13.6849281,47.3935649?overview=full&radiuses=49;49&timestamps=1563459949;1563460007

Polyline changes the order of points

I would like leaflet to connect points in polyline in the same order as they were passed into constructor (L.polyline(route, routeOptions).addTo(map) where route is an array of points), but it seems to me that polyline does not care about order at all. Any suggestions would be highly appreciated.
What makes you think that Leaflet polyline does not care at all about the order in the array of points (coordinates)?
L.polyline(arrayOfLatLngs) should draw a segmented line passing by all the specified coordinates in arrayOfLatLngs, in the order they are set in the array.
Demo: http://jsfiddle.net/ve2huzxw/91/
If it does not behave that way for you, please provide your code and if possible reproduce your issue online (e.g. on jsfiddle) so that people can investigate.

How to get the coordinates of the polygon area

How to get the coordinates of the polygon area:
http://wikimapia.org/#lang=en&lat=49.964473&lon=36.262436&z=12&m=b&show=/20421408/Chervonozavodsky-district
You need to use the place.Search function of The Wikimapia API and enter the latitude, longitude and the name of the place as parameters.
The API returns a lot of data separated in blocks. The one you are interested in is the geometry.
You can make tests with the Wikimapia API to filter the results to your needs. With the lat lon parameters and the district name you provided I was able to get the area you needed as the first result.
The places[0].polygon is what you need. A JSON array of coordinates.
HereĀ“s the url I used to get the results:
http://api.wikimapia.org/?key=example&function=place.search&q=Chervonozavodsky-district&lat=49.964473&lon=36.262436&format=json&pack=&language=en&data_blocks=geometry%2C&page=1&count=1
Note that in this example i made the request for a JSON result. But you can also ask for a XML if you prefer.
Hope it helps!

how to get multiple distance route results for single destination from google api call?

how to get multiple distance route results for single destination from google api call?
starting point and ending point i have to find the distance between them. i have to display the shortest and middle and longest distance for only one destination(ending point).
it has any API provided to me.
Please help me
Advance Thanks.
You have to change the current location latitude,longitude and destination latitude,longitude in below url. You will get the result.
http://maps.googleapis.com/maps/api/directions/json?origin=17.4444,78.4666&destination=17.4393,78.4056&units=imperial&alternatives=true&sensor=false