views:

1178

answers:

3

Hey All,

Is is possible to set a region based on a current location in a mapview only one time. I want my iphone app to get the current location, zoom into that current location, and then allow the user to scroll around. However, because my setRegion code is in my didUpdateToLocation function, every time the current location is updated, so is the region, and I can't scroll around on the map. I tried putting this setRegion code in the viewDidLoad function, but the user's current location isn't initialized at this point, so it doesn't work right.

Any ideas?

A: 

Add a BOOL ivar called say regionHasBeenSet to your class and initialize it to NO in viewDidLoad. In didUpdateToLocation, if regionHasBeenSet is NO then call setRegion and set regionHasBeenSet to YES.

DyingCactus
+3  A: 

On this site there's a downloadable example of what you're after (I think!).

http://blog.objectgraph.com/index.php/2009/04/08/iphone-sdk-30-playing-with-map-kit-part-3/

-James

ing0
A: 

if you end up adding annotations at any point, I recently found this code snippet online which was a huge help for zooming in: http://codisllc.com/blog/zoom-mkmapview-to-fit-annotations/

sw