Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKRoadWidthAtZoomScale in iOS 6?

Tags:

ios

mapkit

From the docs for MKRoadWidthAtZoomScale:

You should not use this function to retrieve road widths in iOS 6 and later.

Is there another function that could be used instead, or is this just missing functionality in iOS 6?

It's odd that the function wasn't deprecated, if you shouldn't use it.

like image 683
Amy Worrall Avatar asked Feb 01 '13 08:02

Amy Worrall


Video Answer


1 Answers

I'd hazard a guess that it wasn't deprecated because the functionality will be added back in at some point. The function still works in iOS 6, as in it doesn't cause a crash when called, even though the output isn't useful.

If you look at the (Apple) Maps app, you can see that when you zoom into a directions path, the width of the path increases at the highest zoom levels. The width of the road increases at those high zoom levels too. Obviously Apple has an internal way to know how wide the roads get when zooming. Maybe it hasn't been fully tested for general release.

Just in case anyone thinks you can still use this function, here's the suggested road widths starting at fully zoomed in (MKZoomScale = 1) and zooming out.

Code:

for (float zoomScale=1; zoomScale>0.00001; zoomScale /= 2) {
    NSLog(@"zoomScale: %f Road Width: %f", zoomScale, MKRoadWidthAtZoomScale(zoomScale));
}

Results:

zoomScale: 1.000000 Road Width: 21.000000
zoomScale: 0.500000 Road Width: 32.000000
zoomScale: 0.250000 Road Width: 60.000000
zoomScale: 0.125000 Road Width: 96.000000
zoomScale: 0.062500 Road Width: 176.000000
zoomScale: 0.031250 Road Width: 288.000000
zoomScale: 0.015625 Road Width: 448.000000
zoomScale: 0.007812 Road Width: 768.000000
zoomScale: 0.003906 Road Width: 1536.000000
zoomScale: 0.001953 Road Width: 2048.000000
...

As for a replacement function, I'd suggest just creating some values that work well for the highest 2 or 3 zoom levels and using a constant value below that.

Here's the Apple maps route overlay at low and high zooms. You can see that the alternative route isn't taking the larger road width into consideration, but the main route width is spot on. Changing the route doesn't affect the alternative route width.

enter image description here

like image 193
nevan king Avatar answered Sep 28 '22 12:09

nevan king