Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin - GoogleMap class move to specific location

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
like image 905
Barney Chambers Avatar asked Nov 01 '25 15:11

Barney Chambers


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.

like image 187
Narendra Sharma Avatar answered Nov 03 '25 08:11

Narendra Sharma


You can move the camera

var latlng = new LatLng(34.9820, 138.5160);
gMap.MoveCamera(CameraUpdateFactory.NewLatLng(latlng));
like image 33
Pavel Yakovlev Avatar answered Nov 03 '25 07:11

Pavel Yakovlev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!