Xamarin.Forms.Googlemaps显示空白

时间:2018-06-08 11:25:19

标签: c# google-maps xamarin.forms

我已经安装了Xamarin.Forms.Googlemaps 2.3.0。但是我可以在Android中看到空白控件的文字" Xamarin.Forms.GoogleMaps"在iOS中,没有。 我哪里错了?

在Androidmanifest中,添加: -

<meta-data android:name="com.google.android.geo.API_KEY" android:value="API_KEY"/>

在xaml中,命名空间是: -

xmlns:gmap="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"

控制是: -

<gmap:Map x:Name="map"
                          Grid.Row="1"
                          HasZoomEnabled="True"
                          HeightRequest="{x:Static local:AppConstants.ActivityLogGfxContainerSize}"
                          InitialCameraUpdate="-23.68, -46.87, 13, 30, 60"
                          IsShowingUser="True"
                          MapLongClicked="map_MapLongClicked"
                          VerticalOptions="FillAndExpand"
                          WidthRequest="{x:Static local:AppConstants.PadThird}" />
xaml.cs中的

: -

 protected override void OnBindingContextChanged()
        {
            base.OnBindingContextChanged();

            this.locationViewModel = viewModel as LocationControlViewModel;

            Check.IsNotNull(locationViewModel);

            map.MyLocationEnabled = true;
            map.MoveToRegion(Xamarin.Forms.GoogleMaps.MapSpan.FromCenterAndRadius(new Xamarin.Forms.GoogleMaps.Position(this.locationViewModel.Latitude, this.locationViewModel.Longitude), Xamarin.Forms.GoogleMaps.Distance.FromMiles(1)));
        }
    private async void map_MapLongClicked(object sender, Xamarin.Forms.GoogleMaps.MapLongClickedEventArgs e)
        {            
            this.locationViewModel.Latitude = e.Point.Latitude;
            this.locationViewModel.Longitude = e.Point.Longitude;
            Xamarin.Forms.GoogleMaps.Pin pin = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type = Xamarin.Forms.GoogleMaps.PinType.Place,
                Position = new Xamarin.Forms.GoogleMaps.Position(this.locationViewModel.Latitude, this.locationViewModel.Longitude),
                Label = "test"
            };
            map.Pins.Clear();
            map.Pins.Add(pin);
            map.MoveToRegion(Xamarin.Forms.GoogleMaps.MapSpan.FromCenterAndRadius(new Xamarin.Forms.GoogleMaps.Position(this.locationViewModel.Latitude, this.locationViewModel.Longitude), Xamarin.Forms.GoogleMaps.Distance.FromMiles(1)));

            var stream = await map.TakeSnapshot();
        }

0 个答案:

没有答案