【问题标题】:google map sdk how to get current location in xamarin iosgoogle map sdk 如何在 xamarin ios 中获取当前位置
【发布时间】:2014-04-04 08:31:13
【问题描述】:

我有如下代码,但“CLLocation loc = mapView.MyLocation;”将 null 分配给 loc 对象,因此我无法获取当前位置。

如何使用 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


    【解决方案1】:

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

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      您需要从 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
                  };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-24
        • 1970-01-01
        • 2023-04-01
        • 1970-01-01
        • 2019-05-15
        • 2014-11-26
        相关资源
        最近更新 更多