Calculating Scale/Distance from Map Resolution and Map Width

3884
4
06-20-2012 11:28 PM
PaulDavis
New Contributor III
I'm trying to display a scale indicator on a map and can't see any built in functionality to do this like I've seen with other examples like the web api (an inbuilt scale control that you can choose to show).

I want to calculate the width of the current map in kilometres and from what I've read the resolution property gives the map's current map units per Point. If I use the maps width, the resolution and the fact that the map units are in meters (divide by 1000).

NSLog(@"Scale: %f, Resolution: %f, Width km: %f", mapView.mapScale, mapView.resolution, (mapView.frame.size.width * mapView.resolution) / 1000);

Can anyone confirm that I'm understanding this ok? Are there any other factors I need to take into consideration?
0 Kudos
4 Replies
RickJones
Occasional Contributor II
The map control's frame isn't going to change as you zoom.

The envelope does though. Use the width of that.


    NSLog(@"%f", self.mapView.visibleArea.envelope.width);
0 Kudos
PaulDavis
New Contributor III
Hi Rick,
thanks for the reply. The resolution changes as you zoom so you get the new value when you subscribe to the MapDidEndZooming notification and check the mapView again. The maps frame not changing is ok as I would like to know how wide the map is (in kilometres) that fits into the current frame.

So given that resolution is units per point and the map is x points wide it should be a straight forward calculation?

I think.....
0 Kudos
RickJones
Occasional Contributor II
We use meters as our unit of measure.

I used a ruler tool in my app to measure the map width. 480
The envelope width returned 480, so I didn't need any further calculations.
0 Kudos
PaulDavis
New Contributor III
I initially calculated the distance from two lat/long points using other built in functions then saw that there were the extra properties on the map that you could use. I get the same result from both methods but when I compared the distance to a measurement taken in the arcgis iPad app for the same locations it's different. In one example my measurement was 2.9km but it was 2.3km in arcgis.

I'll keep looking...
0 Kudos