Xamarin - GoogleMap class move to specific location

Viewed 1258

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
2 Answers

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.

Related