Keeping the current zoom level forms.maps

GuyProvostGuyProvost CAMember ✭✭✭
edited August 2015 in Xamarin.Forms

I'm using Forms.maps top show the users locations while tracking on a map, everything's working fine except that I would like to keep the user's current "zoom level" when I'm in the handler.

The handler's code is :

void HandlePositionChanged(object obj, Geolocator.Plugin.Abstractions.PositionEventArgs e) { map.MoveToRegion(MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(e.Position.Latitude,e.Position.Longitude), Distance.FromMiles(4.0))); }

Here the radius is set to 4 miles, I would like to have it as being the current level the user pinched it!

Looked up top find what I can in the map object to no avail.

Any idea ?

Posts

  • XamDev.2511XamDev.2511 USMember

    Might be a bit late to help, but you can do this:

    map.MoveToRegion(MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(e.Position.Latitude,e.Position.Longitude), map.VisibleRegion.Radius));

  • GuyProvostGuyProvost CAMember ✭✭✭

    Thanks, I'll give it a go. Since I haven't received any hints, I did a lousy workwaroud. I'll give it a try and come back to you!

  • GuyProvostGuyProvost CAMember ✭✭✭

    @XamDev.2511 said:
    Might be a bit late to help, but you can do this:

    map.MoveToRegion(MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(e.Position.Latitude,e.Position.Longitude), map.VisibleRegion.Radius));

    Been a while and gave it a shot, but the map.VisibleRegion is null... Am I missing something ?

  • GuyProvostGuyProvost CAMember ✭✭✭
    edited April 2016

    Got it right... I was trying to access the map.visibleregion before the map had completed it loading process!

    Thanks @XamDev.2511 !

  • RickZicariRickZicari USMember

    Can you show your code?

  • Emixam23Emixam23 USMember ✭✭✭

    So it means you have a method to handle the event of loading finished?

  • GuyProvostGuyProvost CAMember ✭✭✭

    Nope. My position checks are either Timer based or onPositionChanged. The really first PositionChanged may arrives before the map is ready. So I just do a check on null before setting the MoveToRegion.

  • SergioAMGSergioAMG MXMember ✭✭

    Great help @GuyProvost !! I just implemented the same functionality over Xamarin.Forms.GoogleMaps and works like a charm !
    Cheers for your sharing.

  • GuyProvostGuyProvost CAMember ✭✭✭

    @SergioAMG said:
    Great help @GuyProvost !! I just implemented the same functionality over Xamarin.Forms.GoogleMaps and works like a charm !
    Cheers for your sharing.

    Sweet!

Sign In or Register to comment.