开发者

iPhone Mapkit Blue Dot / User Location Region Zoom Question

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 loc开发者_如何学运维ation 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?


On this website there is an example of what I think you are after...

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


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.


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/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜