DEPRECATED-mapbox-ios-sdk icon indicating copy to clipboard operation
DEPRECATED-mapbox-ios-sdk copied to clipboard

Wrong distances for RadiusInMeters - usage of miles instead of kilometers

Open mrsnow-git opened this issue 11 years ago • 5 comments

Function to create circle

RMCircle *circle = [[RMCircle alloc] initWithView:mapView radiusInMeters:10000];

used 10000 not as meters (part of kilometers, 10 km as we can expect), but as part of miles. So used 10000 value represent 16000 meters on real map (16 km or 10 miles).

At page https://www.mapbox.com/mapbox-ios-sdk/examples/drawing-circle/ you have this example and also have example image - using this image you can check it on google maps .

I suppose this (miles but not kilometers) - used in other parts, for projection, distances and so on.

mrsnow-git avatar Oct 07 '14 08:10 mrsnow-git

Hmm, this doesn't sound right. I know that the projection meters are figured properly (e.g. -[RMMapView metersPerPixel] holds the correct equatorial scale), so my first thought was that perhaps RMCircle isn't accounting for latitude. But it seems to be doing this correctly:

https://github.com/mapbox/mapbox-ios-sdk/blob/509fa7df46ebd654d130ab2f530a8e380bf2bd59/MapView/Map/RMCircle.m#L91

I will investigate further. @mrsnow-git could you provide the comparison image that you used?

incanus avatar Oct 07 '14 18:10 incanus

There is some images for two examples. Sorry for heavy traffic. First example from pointed site and example, Washington, DC - I set the radius to 10000 (in both examples). At simulator screen we can see how it looks on map, so we can measure this on google map for example. on next screens we can see the real distances, it's more big than 10000 meters. Second example is over the Moscow, Russia. There is screen from our local russian map service, and also can measure the distance.

As I know the google used not real Mercator projection, Yandex used real one. But for 10km on this longitude it's doesn't really matter.

Another one thing - the function used radiusInMeters - so we can measure the circle diameter as 2*radius - in this example it must to be 20000, but we see the differences...

@incanus try to measure some thing by yourself, maybe I'm wrong in some my tests (maybe I make some changes in my own app and now can't find it and cant remember it)?

I see what there is a problem, but I can't exactly find the problem point. My proposal about miles it's only proposal...

a0 a1 a2 a3 a4 a5 a6 b1 b2 b3 b4 b5 b6 b7

mrsnow-git avatar Oct 07 '14 22:10 mrsnow-git

my first thought was that perhaps RMCircle isn't accounting for latitude. But it seems to be doing this correctly:

https://github.com/mapbox/mapbox-ios-sdk/blob/509fa7df46ebd654d130ab2f530a8e380bf2bd59/MapView/Map/RMCircle.m#L91

This should be dividing by the cosine of the latitude in degrees, not radians. 39 degrees (~Washington) = 0.68 radians. cos(0.68) = 0.9999 (basically no change). cos(39) = 0.777 which would scale things correctly.

ajashton avatar Oct 09 '14 15:10 ajashton

Oh, great catch. That'd do it. I should've checked that. Will fix.

incanus avatar Oct 09 '14 15:10 incanus

projectedLocation is never set in RMCircle (or RMMapLayer), but is in the associated annotation, so using that works. Radians are correct (for C cos())

CGFloat latRadians = [[mapView projection] projectedPointToCoordinate:annotation.projectedLocation].latitude * M_PI / 180.0f;

Looks like only RMShape uses the RMMapLayer projectedLocation, so to avoid confusion it should probably be removed from RMMapLayer and kept private to RMShape as the location of the first point in the shape.

tracyharton avatar Mar 22 '15 20:03 tracyharton