google map sdk如何获取xamarin ios中的当前位置

问题描述 投票:1回答:2

我有一个像下面的代码,但“CLLocation loc = mapView.MyLocation;”assigne null到loc对象,所以我不能采取cuurent位置。

如何使用google map sdk for ios获取我在xamarin for ios的当前位置。

//and many other using
using Google.Maps;

public partial class MapNavigationController : UIViewController
{   

MapView mapView; 

   public override void LoadView ()
        {
            base.LoadView ();

            var camera = CameraPosition.FromCamera (latitude: 7.2935273, 
                longitude: 80.6387523, 
                zoom: 13);
            mapView = MapView.FromCamera (RectangleF.Empty, camera);

            mapView.MyLocationEnabled = true;
            mapView.MapType = MapViewType.Hybrid;
            CLLocation loc = mapView.MyLocation;
                        Console.WriteLine("tapped at " + loc.Coordinate.Latitude + "," +loc.Coordinate.Longitude);
                 }
 }
ios google-maps xamarin.ios xamarin
2个回答
0
投票

我对iOS中的谷歌地图不太熟悉。但我认为不可能从MapView获取当前位置。您可以显示它(通过启用选项(showOwnLocation或类似的东西))。如果您想以正确的方式执行此操作,则必须使用iOS SDK中的CLLocationManager。我现在没有可用的样本,但如果你谷歌它你会找到一些。

希望这会对你有所帮助。


0
投票

您需要从CCLocationManager获取该信息,如下所示:

CameraPosition camera = CameraPosition.FromCamera(latitude: App.MyLatitude,
                                                                  longitude: App.MyLongitude,
                                                                  zoom:50);
            mapView = MapView.FromCamera(CGRect.Empty, camera);
            mapView.Settings.ScrollGestures = true;
            mapView.Settings.ZoomGestures = true;
            mapView.MyLocationEnabled = true;
            mapView.MapType = MapViewType.Satellite;
            CLLocation loc = iPhoneLocationManager.Location;


            // My position
            var Marker = new Marker()
            {
                Title = App.PinTitle,
                Snippet = App.PinLabel,

                Position = new CLLocationCoordinate2D(latitude: loc.Coordinate.Latitude, longitude: loc.Coordinate.Longitude),
                Map = mapView
            };
© www.soinside.com 2019 - 2024. All rights reserved.