我有一个像下面的代码,但“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中的谷歌地图不太熟悉。但我认为不可能从MapView获取当前位置。您可以显示它(通过启用选项(showOwnLocation或类似的东西))。如果您想以正确的方式执行此操作,则必须使用iOS SDK中的CLLocationManager。我现在没有可用的样本,但如果你谷歌它你会找到一些。
希望这会对你有所帮助。
您需要从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
};