void OnLocationChosen(object sender, EventArgs e) { // Crosshair is a regular ImageView centered on the MapView, // Translate crosshair's coordinates to a position on the map var parameters = (RelativeLayout.LayoutParams)ContentView.Crosshair.LayoutParameters; var x = parameters.LeftMargin + parameters.Width / 2; var y = parameters.TopMargin + parameters.Height / 2; var screen = new ScreenPos(x, y); ContentView.MapView.ScreenToMap(screen); MapPos position = ContentView.MapView.ScreenToMap(screen); PointClient.AddUserMarker(position); // Center marker on currently visible area (partically hidden by popup) var mapBounds = new MapBounds(position, position); y = ContentView.Popup.VisibleY / 2; screen = new ScreenPos(x, y); var screenBounds = new ScreenBounds(screen, screen); ContentView.MapView.MoveToFitBounds(mapBounds, screenBounds, false, 0.2f); // Translate internal units to lat/lon position = PointClient.Projection.ToLatLong(position.X, position.Y); LocationClient.MarkerLatitude = position.X; LocationClient.MarkerLongitude = position.Y; RunOnUiThread(delegate { ContentView.Popup.Show(); }); }
void OnLocationChosen(object sender, EventArgs e) { // Scale needs to be accounted for separetly, // multiply all iOS view coordinates by scale to get real values nfloat scale = UIScreen.MainScreen.Scale; // Crosshair is a regular ImageView centered on the MapView, // Translate crosshair's coordinates to a position on the map var parameters = ContentView.Crosshair.Frame; var x = (parameters.X + parameters.Width / 2) * scale; var y = (parameters.Y + parameters.Height / 2 - Device.TrueY0) * scale; var screen = new ScreenPos((float)x, (float)y); ContentView.MapView.ScreenToMap(screen); MapPos position = ContentView.MapView.ScreenToMap(screen); PointClient.AddUserMarker(position); // Center marker on currently visible area (partically hidden by popup) var mapBounds = new MapBounds(position, position); y = (ContentView.Popup.VisibleY / 2) * scale; screen = new ScreenPos((float)x, (float)y); var screenBounds = new ScreenBounds(screen, screen); ContentView.MapView.MoveToFitBounds(mapBounds, screenBounds, false, 0.2f); // Translate internal units to lat/lon position = PointClient.Projection.ToLatLong(position.X, position.Y); LocationClient.MarkerLatitude = position.X; LocationClient.MarkerLongitude = position.Y; InvokeOnMainThread(delegate { ContentView.Popup.Show(); ContentView.CancelCrosshairMode(); }); }