【发布时间】:2013-02-10 18:11:39
【问题描述】:
有时需要您将地图中心设置在用户当前位置但不显示蓝点。假设您只想拥有该区域,但您不希望该用户专注于他在地图上的位置。你想让他们专注于地图的其他对象。
我们如何获取用户位置但不显示蓝点?
【问题讨论】:
标签: ios iphone xamarin.ios mkmapview
有时需要您将地图中心设置在用户当前位置但不显示蓝点。假设您只想拥有该区域,但您不希望该用户专注于他在地图上的位置。你想让他们专注于地图的其他对象。
我们如何获取用户位置但不显示蓝点?
【问题讨论】:
标签: ios iphone xamarin.ios mkmapview
Tim 的答案相当于 Monotouch:
mapView .ShowsUserLocation =true ;
mapView.DidUpdateUserLocation += (sender, e) => {
if (mapView.UserLocation != null) {
CLLocationCoordinate2D location;
location.Latitude = mapView.UserLocation .Coordinate .Latitude ;
location.Longitude = mapView.UserLocation .Coordinate.Longitude;
mapView .CenterCoordinate =location ;
mapView .ShowsUserLocation =false ;
}
};
【讨论】:
您可以通过
获取位置mapView.userLocation
所以,用它来设置mapView的中心:
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.02 / 10; // zoom level
span.longitudeDelta=0.02 / 10;
CLLocationCoordinate2D location;
location.latitude = mapView.userLocation.coordinate.latitude;
location.longitude = mapView.userLocation.coordinate.longitude;
region.span=span;
region.center=location;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
然后,您可以使用以下命令隐藏蓝点:
[mapView setShowUserLocation:NO];
不确定与此 Objective-C 代码等效的实际 MonoTouch 是什么,但它应该以类似的名称命名。
【讨论】: