我有一个类似下面的代码但是" CLLocation loc = mapView.MyLocation;
" assigne null到loc对象,所以我不能采取cuurent位置。
如何使用谷歌地图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);
}
}
答案 0 :(得分:0)
我对iOS中的Google地图不太熟悉。 但我认为不可能从MapView获取当前位置。 您可以显示它(通过启用选项(showOwnLocation或类似的东西))。 如果您想以正确的方式执行此操作,则必须使用iOS SDK中的CLLocationManager。我现在没有可用的样本,但如果你谷歌它会找到一些。
希望这可以帮到你。
答案 1 :(得分: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
};