Xamarin.iOS에서 Google Maps SDK를 사용하여 장치의 현재 위치를 얻으려고하고 있는데 다음 코드가 있지만 예외가 발생합니다.Xamarin iOS Google지도 SDK - 예외 (mapView.AddObserver())
나는이 내 코드입니다
using Google.Maps;
자 마린에서 iOS 용 Google지도 SDK를 가져온 : 다음
MapView gmapView;
public override void ViewDidLoad()
{
base.ViewDidLoad();
CameraPosition camera = CameraPosition.FromCamera (latitude: 40.7056308,
longitude: -73.9780035,
zoom: 13);
mapView = MapView.FromCamera (new RectangleF(0, 0, View.Frame.Width, View.Frame.Bottom - 50), camera);
mapView.Settings.CompassButton = true;
mapView.Settings.MyLocationButton = true;
// Listen to the myLocation property of GMSMapView.
mapView.AddObserver (this, new NSString ("myLocation"), NSKeyValueObservingOptions.New, IntPtr.Zero);
// More code ...
// ...
// Ask for My Location data after the map has already been added to the UI.
InvokeOnMainThread (()=> mapView.MyLocationEnabled = true);
}
나는 호출하는 메소드를 정의 할 때 사용자의 위치 변경 :
public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
if (!firstLocationUpdate) {
// If the first location update has not yet been recieved, then jump to that
// location.
firstLocationUpdate = true;
var location = change.ObjectForKey (NSValue.ChangeNewKey) as CLLocation;
mapView.Camera = CameraPosition.FromCamera (location.Coordinate, 14);
}
}
하지만 다음과 같은 예외가 발생하며이 문제에 봉착했습니다. RA는 행운과 동시에 :/
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: <MapViewController: 0x1b6648c0>: An - observeValueForKeyPath:ofObject:change:context: message was received but not handled.