4

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.

enter image description here

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

Community
  • 1
  • 1
fyasar
  • 3,996
  • 2
  • 42
  • 55

3 Answers3

9

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.

myell0w
  • 2,200
  • 2
  • 21
  • 25
  • Hey myell0w, I changed my code according to your comment and it worked as expected. Thanks for quick response. – fyasar Jun 07 '11 at 22:39
  • MTLocation now has a category-method on MKMapView to automatically do this resizing for you: [self.mapView sizeToFitTrackingModeFollowWithHeading] – myell0w Dec 31 '11 at 12:51
  • just change u r device angle,then the map will comes in correct way. – Hari1251 Oct 16 '12 at 13:08
  • @myell0w I am working on something similar and have the same issue as above my map is iPad sized at currently 768 wide x 863 high but I dont understand the calculation any chance you could help? – Alex McPherson Apr 23 '13 at 22:16
0

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.

Autonomous
  • 8,935
  • 1
  • 38
  • 77
0
  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.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105