Rotating MapView according to compass
I'm working on Map application that needs to work like original MapView on iOS. I need to rotate mapview according to compass heading value. I tried MTLocation example also 开发者_开发问答I also tried this answer But my results is not good.
Please see the screen shot.
When I rotate mapview according to heading value Map is rotating but as you can see on screen tiles is missing.
How can I solve this display problem ?
Regards - Fatih
Hy,
I'm the author of MTLocation. Thanks for using it by the way! For this to work you have to make sure, that your MKMapView is a subview of your ViewController's view (and not the view itself). Then you have to increase the frame of your mapView with a simple Pytaghoras - calculation: the width and height must be at least as big as the diagonal: sqrt(visibleWidth[320]^2 + visibleHeight[480-88]^2) = 506.
So that means
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(-100,-100,520,520)];
Hope that helped, please consider upvoting if it fixed your problem.
You can consider using a bigger frame for the
MKMapView
object. It should probably be a square with each side equal to the length of the device's diagonal. The problem with this approach is that there are regions of this object that the user won't see but we process information like views for annotations related to that region anyway. Other properties likevisibleMapRect
would be least helpful.Another alternative would be to be zoom in by scaling the
MKMapView
object on rotation. But this might make the map blurry (untested). You could zoom out on the region displayed in the map but it could lead to frequent refreshes. You can look at a middle ground where you don't zoom out until the map is rotated over a certain angle. You can also look at using two views where one of the views is off screen and updated so that it can replace the view after a certain amount of rotation so that it feels seamless.
I am working towards making my own maps application in iPhone. I want my maps to rotate as the user turns. I tried setUserTrackingMode
available in iOS 5, but due to some reason it doesn't work. So I decided to take help of MTLocation
framework here.
Till now I have done the following.
- created a new project and copied all .m and .h files in that.
- Import
MapKit.h
andMTLocation.h
. - In
Viewcontroller.h
, defined property formapView
(should I define a property forlocateMeItem
). - In
ViewDidLoad
, paste the code given at the end of the page here.
I get a few errors:
- Can't see the
locateMe
button when created programatically. - Undefined property
headingEnabled
. myCustomSelector
has no effect.self.toolbar
- toolbar is not a instance ofViewController
.
I have tried a code at gist[dot]github[dot]com/1373050 too, but I get similar errors.
Can anybody explain a detailed procedure of this.
精彩评论