amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 346 forks source link

Default Map Positon #667

Closed davidbuckleyni closed 4 years ago

davidbuckleyni commented 4 years ago

For the life of me I can't see how I set up the default map position when the map firsts start up or does it go to the first marker position.

Pietervdw commented 4 years ago

I need the map to open at the user's current position. So what I do is get the current position using Xamarin Essentials GeoLocation. I then use the MoveToRegion method of the map, e.g:

map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(YOURLATITUDEHERE, YOURLONGITUDEHERE), Distance.FromMeters(1000)), false);

Not sure if there's a better way, but this works for me.

amay077 commented 4 years ago

map.MoveToRegion is deprecated.

You can use map.InitialCameraUpdate property in you Page's constructor or XAML.

https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/f7d61668fe1e022f717617a82239efc519405160/XFGoogleMapSample/XFGoogleMapSample/ShapesPage.xaml.cs#L152

https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/f7d61668fe1e022f717617a82239efc519405160/XFGoogleMapSample/XFGoogleMapSample/BasicMapPage.xaml#L216-L218