Place pin randomly on road - iOS Maps Swift - ios

I'm trying to figure out how I can place an annotation randomly on a road.
I can randomly position an annotation onto a map, but I would like this annotation to be on a road and not in a shopping mall/building/home etc.
Does anyone know the best way I can do this?

One strategy would be to take your random coordinate and then reverse geocode it. That will provide an address closest to your random coordinate. Once reverse geocoded, you can use the result of that process to create your annotation.

Related

Drawing Polyline on an ios Mapview

In my Xamarin ios app I have to draw the path as user walks,
I am planning to do this by drawing Polyline to a Map view by fetching Lattitude & Longitude from CClocationManager, But I have to deal with N number of Lattitude & Longitude in this case,
Is there any simple approach to do this? In our scenario We won't be knowing the destination , User will Just start a run from a point and we have to track his path on map by drawing a line, How could I do this?
A possible solution could be to save the current last known position, which also represents you endpoint of a polyline. On a location change use it as a starting point for the next polyline. That way you draw the route with multiple polylines piece by piece.

How to show indoor annotations on MKMapView

I need to show an indoor floor plan in a MKMapView. So far I have managed to load custom map tiles into MKMapView. But when I try to show annotations it does not show in correct location. The space between latitudes are not equal. I think it’s because MKMapView maps the globe into flat surface. But in my case I need to show annotations in a flat surface. Any idea how to do this?
EDIT : Anyone know how to convert geographic coordinates to cartesian coordinates? That will solve this problem
Apple just updated its demo project:
https://developer.apple.com/library/prerelease/ios/samplecode/footprint/Introduction/Intro.html
Take a look, there are information about how to translate geolocation (spherical) to flat location.

Identify when MKRoutestep finishes

I am trying to implement a turn by turn navigation system in iOS using MKDirections API. I am able to get the directions of the route and can draw the polyline on the map, and when navigation starts the app start showing the instructions using the MKRouteStep object in Steps array. Now the problem is, since the distance in the MKRouteStep object is the distance that the user covers while traversing the path of the step I am unable to identify how to calculate this distance. Is there any way to calculate this distance ? Currently I am calculating the distance between two coordinates i.e the coordinate when last instruction was shown with the current location of user and if this distance is equal to the distance mentioned in MKRouteStep I am showing the next instruction, due to which it is delaying the instruction to be delivered to user.
If there is any way to identify the coordinate or region where this MKRouteStep ends I can calculate whether the user is in that region or not and then show the next instruction. May be this can work what are your thoughts, but for this how will I know the coordinate or region where this MKRouteStep ends from polyline array of MKRouteStep?
Please suggest if there is any other good solution for this. Any help is highly appreciated.
Thanks.
Since no one has answered to my question I am answering it myself so that it may help someone looking for the same.
So instead of using distance value of MKRouteStep to calculate when to show next instruction, we can use the last coordinate of polyline array provided by MKRouteStep. For example:
MKMapPoint mapPointForEndOfRouteStep = routeStep.polyline[routeStep.polyline.pointCount - 1];
Now you can create a region around it and check whether your current location lies in this region or not.

Finding out if a space is occupied by a road/building/water with MapKit? [duplicate]

is there any way to determine which type of area you are in from a MKMapView? I.e. if the centre of the map is in the ocean we can tell the user: the centre of the map is above the ocean, or if the map is centred above a green area: the centre of the map is above parkland...
The only way I can think of to do this is to create a screenshot of the visible screen and analyse the colour of each bit by using some method such as this: iOS -- detect the color of a pixel?
However I would be interested to know if there is an easier way that anyone can think of!
EDIT
To make it more clear what I'm looking for, I'm basically looking for a way to turn a section of a map into a top down level for a game, with different areas determined by the areas of the map...
A CLPlacemark has a couple of properties: inlandWater and ocean which tell you when the placemark is in water. I think you can get a placemark from the geocoder.
It also has areasOfInterest which will give you parks and landmarks.
there is no foolproof way BUT CLGeocoder can reverse geocode a coordinate to an address and that would give you stuff like:
0/0 = ...., ocean
51/10 = ..., germany
-90/10 = ..... , united states
and so on

IOS MKMapView sidewalk

Im working with Mapkit and I trying to draw a line in the "sidewalks" (border of the street),right now I'm looking for ideas on how I could start this task, thanks for your help.
notes: I know how to works with mkpolyline and coordinates
http://s30.postimg.org/7rnmdjzu9/mapa.png
You do not have access to the information that qualifies as a road inside the MKMapView. so, in order to be able to draw into the border of the street you will need to access the information that qualifies as a street (the coordinates of the road) or analyzing the view and changing the specific color represented by the border of the street (this is not public API, you will need to dig around the view hierarchy).

Resources