Refresh Google Map dinamically

I'm building an app that shows a map, and the problem is that I get a black window where the map has to be shown.
When I press some map window button (zoom, or pan) the map is displayed without problem. So I think a possible solution would be refresh the map once the page is loaded.

Is there any dynamic way to refresh a map, after the page is loaded?
Or maybe set a different zoom, by code?

Thanks.

I'm using xamarin forms, without XAML.

Answers

  • MavenDeveloperMavenDeveloper USMember

    Can you post the code?

  • PabloPardoPabloPardo ESMember

    @MavenDeveloper here is the page.

    public class MapPg : ContentPage
        {
            Map map;
            Place lugar;
            public MapPg (Place lugar)
            {
                this.lugar = lugar;
                Position p = new Position(lugar.lat, lugar.lon);
    
                String l = lugar.lugarnombre+" \n"+lugar.direccion+" \n"+lugar.ciudad;
                var pin = new Pin () {
                    Position = p,
                    Label = l
                };
                map = new Map(MapSpan.FromCenterAndRadius(
                    p, Distance.FromMiles(0.3))) {
                    IsShowingUser = true,
                    HeightRequest = 100,
                    WidthRequest = 960,
                    VerticalOptions = LayoutOptions.FillAndExpand
                };
    
                //add pin
                map.Pins.Add (pin);
    
    
    
                var stackCP = new StackLayout { 
                    Spacing = 10,
                    Orientation = StackOrientation.Horizontal
                };
    
                stackCP.Children.Add (new Label{Text = lugar.cp, FontSize=20 });
                stackCP.Children.Add (new Label{Text = lugar.ciudad, FontSize=20});
    
                var stackTlf = new StackLayout { 
                    Spacing = 10,
                    Orientation = StackOrientation.Horizontal
                };
    
                stackTlf.Children.Add (new Label{Text = lugar.telefono, FontSize=20});
                stackTlf.Children.Add (new Label{Text = lugar.mail, FontSize=20});
    
                var stackInfo = new StackLayout { Spacing = 0 };
                stackInfo.Children.Add (new Label{Text = lugar.lugarnombre, FontAttributes=FontAttributes.Bold, FontSize=40});
                stackInfo.Children.Add (new Label{Text = lugar.direccion, FontSize=20});
                stackInfo.Children.Add (stackCP);
                stackInfo.Children.Add (stackTlf);
    
                var stack = new StackLayout { Spacing =10 };
    
                stack.Children.Add (stackInfo);
    
    
                Content = stack;
                stack.Children.Add(map);
            }
        }
    
  • MitchMilamMitchMilam USMember ✭✭✭

    @PabloPardo on your StackLayout stack, try adding Vertical and Horizontal Options to FillAndExpand

  • PabloPardoPabloPardo ESMember

    Thanks @MitchMilam , I've tried with:

    var stack = new StackLayout {
                    Spacing =10 , 
                    VerticalOptions = LayoutOptions.FillAndExpand, 
                    HorizontalOptions = LayoutOptions.FillAndExpand
                };
    
                stack.Children.Add (stackInfo);
    
    
                Content = stack;
                stack.Children.Add(map);
    

    But nothing changes. Maybe changing the order?

  • MitchMilamMitchMilam USMember ✭✭✭

    @PabloPardo try this:

            stack.Children.Add(map);
            Content = stack;
    
  • PabloPardoPabloPardo ESMember

    @MitchMilam is what I was trying right now.
    Same result :(

  • RendyDelRosarioRendyDelRosario DOUniversity ✭✭✭
    edited May 2015

    Try:

    mapView.PropertyChanged+= (sender, e) => {
                        if(e.PropertyName=="VisibleRegion")
                        {
                            mapView.VisibleRegion.WithZoom (20);
    
                        }
    };
    
Sign In or Register to comment.