user2970419 user2970419 - 3 months ago 30
iOS Question

distance to pixel conversion for Xamarin.iOS

I'm trying to find distance to pixel conversion for Xamarin.iOS. I know this is how you do it natively, but how would you do this in Xamarin / c#??

MKCoordinateRegion myRegion = MKCoordinateRegionMakeWithDistance(mapView.centerCoordinate, 400, 0);

CGRect myRect = [mapView convertRegion: myRegion toRectToView: nil];
NSLog(@"width for 400m is %f", myRect.size.width);

Any help or guidance would be greatly appreciated!! Thanks!

Answer

ObjC:

MKCoordinateRegion myRegion = MKCoordinateRegionMakeWithDistance(mapView.centerCoordinate, 400, 0);
CGRect myRect = [mapView convertRegion: myRegion toRectToView: nil];
NSLog(@"width for 400m is %f", myRect.size.width);

Xamarin.iOS Conversion:

var myRegion = MKCoordinateRegion.FromDistance(mapView.CenterCoordinate, 400, 0);
var myRect = mapView.ConvertRegion(myRegion, null);
Console.WriteLine($"width for 400m is ${myRect.Size.Width}");