1

有时需要您将地图中心设置在用户当前位置但不显示蓝点。假设您只想拥有该区域,但您不希望该用户专注于他在地图上的位置。你想让他们专注于地图的其他对象。

我们如何获取用户位置但不显示蓝点?

4

2 回答 2

5

相当于 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 ;

            }
        };
于 2013-02-10T20:24:28.753 回答
1

您可以通过以下方式获取位置

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 是什么,但应该以类似的方式命名。

于 2013-02-10T19:26:42.453 回答