开发者

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.

Rotating MapView according to compass

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.


  1. 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 like visibleMapRect would be least helpful.

  2. 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.

  1. created a new project and copied all .m and .h files in that.
  2. Import MapKit.h and MTLocation.h.
  3. In Viewcontroller.h, defined property for mapView (should I define a property for locateMeItem).
  4. In ViewDidLoad, paste the code given at the end of the page here.

I get a few errors:

  1. Can't see the locateMe button when created programatically.
  2. Undefined property headingEnabled.
  3. myCustomSelector has no effect.
  4. self.toolbar- toolbar is not a instance of ViewController.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜