// Two points in rectangular co-ordinate system create a rectange static EastSouthDistance FetchRect(MKMapPoint fromAnchorMKPoint, MKMapPoint toPoint) { double latitude = MKMapPoint.ToCoordinate(fromAnchorMKPoint).Latitude; nfloat metersPerMapPoint = (nfloat)MKGeometry.MetersPerMapPointAtLatitude(latitude); var eastSouthDistance = new EastSouthDistance { East = (nfloat)(toPoint.X - fromAnchorMKPoint.X) * metersPerMapPoint, South = (nfloat)(toPoint.Y - fromAnchorMKPoint.Y) * metersPerMapPoint }; return(eastSouthDistance); }
// Convert the specified geographic coordinate to floorplan point public CGPoint Convert(CLLocationCoordinate2D coordinate) { // Get the distance east & south with respect to the first anchor point in meters EastSouthDistance rect = FetchRect(fromAnchorMKPoint, MKMapPoint.FromCoordinate(coordinate)); // Convert the east-south anchor point distance to pixels (still in east-south) var scaleTransform = CGAffineTransform.MakeScale(PixelsPerMeter, PixelsPerMeter); CGPoint pixelsXYInEastSouth = scaleTransform.TransformPoint(new CGPoint(rect.East, rect.South)); // Rotate the east-south distance to be relative to floorplan horizontal // This gives us an xy distance in pixels from the anchor point. var rotateTransform = CGAffineTransform.MakeRotation(radiansRotated); CGPoint xy = rotateTransform.TransformPoint(pixelsXYInEastSouth); // From Anchor point may not be top letf corner. // however, we need the pixels from the (0, 0) of the floorplan // so we adjust by the position of the anchor point in the floorplan xy.X += fromAnchorFloorplanPoint.X; xy.Y += fromAnchorFloorplanPoint.Y; return(xy); }
// Two points in rectangular co-ordinate system create a rectange static EastSouthDistance FetchRect (MKMapPoint fromAnchorMKPoint, MKMapPoint toPoint) { double latitude = MKMapPoint.ToCoordinate (fromAnchorMKPoint).Latitude; nfloat metersPerMapPoint = (nfloat)MKGeometry.MetersPerMapPointAtLatitude (latitude); var eastSouthDistance = new EastSouthDistance { East = (nfloat)(toPoint.X - fromAnchorMKPoint.X) * metersPerMapPoint, South = (nfloat)(toPoint.Y - fromAnchorMKPoint.Y) * metersPerMapPoint }; return eastSouthDistance; }