In Xamarin's inbuilt Map class, you can use the Map.MoveToRegion(New Position(latitude, longitude)) function to go to an area on the map. I am using the GoogleMap nuget package, and can't seem to find a similar in built function. Is there a function for this with the GoogleMap plugin, and if so, what is it?
GoogleMap gMap = new GoogleMap();
//gMap.MoveToRegion(New Position(34.9820, 138.5160)); <-- something like this
To move the region use below code where
gMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(Latitude, Longitude), Xamarin.Forms.GoogleMaps.Distance.FromMiles(5)));
and use moveCamera to fit two points to bounds(phone screen)
var bounds = Xamarin.Forms.GoogleMaps.Bounds.FromPositions(gMap.Polylines.SelectMany(poly => poly.Positions));
var newBoundsArea = CameraUpdateFactory.NewBounds(bounds, 5);
await gMap.MoveCamera(newBoundsArea);
Where 5 is padding.
You can move the camera
var latlng = new LatLng(34.9820, 138.5160);
gMap.MoveCamera(CameraUpdateFactory.NewLatLng(latlng));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With