Display a CLRegion on a map view - ios

I have a region of of a CLPlacemark declared by
let placeRegion = placemark?.region
According to the Apple docs this is
The geographic region associated with the placemark.
Is it possible to display this region on a map view?
I am not actually sure what a region of a placemark is. Does anyone know if it is just a circular region with a fixed radius around the placemark, or is the region shape sometimes tailored to match the real-life area of the place, for example, the shape of the building of the place?
Thanks

I think it would depend on the origin of the CLPlacemark. While most will come back as CLCircularRegion, you could define a custom CLRegion class that fits a different shape with multiple coordinates and map coordinates from the custom CLRegion to MKPolygon to display the region on the map view.

Related

MKMapView - to keep user at center and cover route drawn on mapview on the screen

I'm trying to achieve as follows:
User should always be at the center of the screen on MKMapView.
Route is drawn on the map as user will move.
I know, i can calculate the region to cover all the tracked points on the screen.
But here's my problem:
When i calculate the MKCoordinateRegion and setting it, it just fits the region that is best fitting to the screen but as soon as i'm trying to place user at center, a part of the line drawn on the MKMapView goes out of the screen.
Can anybody face this problem or any suggestions to handle this specific case, any help will be highly appreciated.
Thanks in advance.
I have accomplished it as follows:
Calculate the distance of farthest point from the user's current location (or any point you want to keep at the center).
Calculate the region, with your center point(user's current location in my case) and double the distance calculated above and make a region using te following code:
CLLocationCoordinate2D loc = [myLocation coordinate];
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance(loc, distance * 2, distance * 2);
Set the region on the MapView and the trail will be shown inside the screen keeping user's location at the center.
Thanks.

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.

how to get latitude and longitude by view coordinates?

I am developing iPhone app and using google map. I used UIView for drawing region. Now I have implemented the touch event methods so how can i get longitude and latitude by view coordinates where user click on view??
As I understand your question You need to create MKMapView that will give you the map property.
https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html
Have you tried with - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view.
It converts the specified points to coordinates point.
CLLocationCoordinate2D touchCoords = [self convertPoint:TOUCH_POINT toCoordinateFromView:YOUR_VIEW];

MKMapView show extra zoomed region. How?

I need to show very small area (30x30 meters) on MKMapView. Setting appropriate region or visibleMapRect doesn't work. MapView shows much bigger region.
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([centerLocation coordinate], 30, 30);
[mapView setRegion:region];
It seems with extra small regions MapView corrects with regionThatFits method before update map.
Manually zoom allows displaying such region.
MapKit is not really designed for such high-zoom indoor uses. You may want to check out alternatives such as the open source MapBox iOS SDK, which has been used for indoor applications. In particular iOS 7's iBeacons technology as well may be useful to you for indoor triangulation and higher accuracy than something like GPS, which was neither designed for indoor nor high-zoom use.
According to Apple docs:
When setting a new region, the map may adjust the value in the region
parameter so that it fits the visible area of the map precisely. This
is normal and is done to ensure that the value in the region property
always reflects the visible portion of the map. However, it does mean
that if you get the value of that property right after calling this
method, the returned value may not match the value you set. (You can
use the regionThatFits: method to determine the region that will
actually be set by the map.)
So, when you apply distance, it creates the region which is best fit for your request. It will not be exactly same as what you have requested.
Also, 30*30 meters is very very high zoom level which might not be supported. Hope it will help.

Find out which type of area you are in from MKMapView

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

Resources