![](/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.