![](/img/trans.png)
[英]IOS Google Map SDK - Google Map not updating to current location
[英]google map sdk how to get current location in xamarin ios
我有一个类似下面的代码,但是“ CLLocation loc = mapView.MyLocation;
”将NULL分配给loc对象,所以我不能获取当前位置。
如何使用iOS的Google Map sdk获取我在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不太熟悉。 但我认为无法从MapView获取当前位置。 您可以显示它(通过启用一个选项(showOwnLocation或类似的东西))。 如果您想以正确的方式进行操作,则必须使用iOS SDK中的CLLocationManager进行操作。 我目前没有样品,但是如果您用Google搜索,就会发现一些样品。
希望这对您有帮助。
您需要从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
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.