Bra*_*don 6 iphone xcode objective-c ios
我有一个纬度和经度坐标,我想集中我的地图.它们存储为NSStrings并转换为以下位置:
NSString *placeLatitude = [elementCoords objectForKey:@"placeLatitude"];
NSString *placeLongitude = [elementCoords objectForKey:@"placeLongitude"];
CLLocationCoordinate2D location;
location.latitude = [placeLatitude doubleValue];
location.longitude = [placeLongitude doubleValue];
Run Code Online (Sandbox Code Playgroud)
我如何修改以下内容以不关注用户的当前位置,而是关注上面指定的纬度和经度?
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.05;
mapRegion.span.longitudeDelta = 0.05;
Run Code Online (Sandbox Code Playgroud)
MKCoordinateRegion region;
CLLocation *locObj = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake([placeLatitude doubleValue], [placeLongitude doubleValue])
altitude:0
horizontalAccuracy:0
verticalAccuracy:0
timestamp:[NSDate date]];
region.center = locObj.coordinate;
MKCoordinateSpan span;
span.latitudeDelta = 1; // values for zoom
span.longitudeDelta = 1;
region.span = span;
[self.mapView setRegion:region animated:YES];
Run Code Online (Sandbox Code Playgroud)
我会用setCenterCoordinate:animated:它来移动地图焦点.如果您正在加载视图并希望立即将其设置为正确的位置,请设置animated:NO,否则,如果要平移地图以平滑居中,location则设置animated:YES
[mapView setCenterCoordinate:location animated:YES];
当然,这不会改变地图视图的缩放级别.如果要更新缩放级别,则应使用setRegion:animated:.例如,如果要近距离放大两倍:
// Halve the width and height in the zoom level.
// If you want a constant zoom level, just set .longitude/latitudeDelta to the
// constant amount you would like.
// Note: a constant longitude/latitude != constant distance depending on distance
// from poles or equator.
MKCoordinateSpan span =
{ .longitudeDelta = mapView.region.span.longitudeDelta / 2,
.latitudeDelta = mapView.region.span.latitudeDelta / 2 };
// Create a new MKMapRegion with the new span, using the center we want.
MKCoordinateRegion region = { .center = location, .span = span };
[mapView setRegion:region animated:YES];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9026 次 |
| 最近记录: |