iphone – 使用MKCoordinateRegion在NSString纬度和经度坐标上聚
发布时间:2020-12-14 19:52:06 所属栏目:百科 来源:网络整理
导读:我有一个纬度和经度坐标,我想集中我的地图.它们存储为NSStrings并转换为以下位置: NSString *placeLatitude = [elementCoords objectForKey:@"placeLatitude"];NSString *placeLongitude = [elementCoords objectForKey:@"placeLongitude"];CLLocationCoord
我有一个纬度和经度坐标,我想集中我的地图.它们存储为NSStrings并转换为以下位置:
NSString *placeLatitude = [elementCoords objectForKey:@"placeLatitude"]; NSString *placeLongitude = [elementCoords objectForKey:@"placeLongitude"]; CLLocationCoordinate2D location; location.latitude = [placeLatitude doubleValue]; location.longitude = [placeLongitude doubleValue]; 我如何修改以下内容以不关注用户的当前位置,而是关注上面指定的纬度和经度? MKCoordinateRegion mapRegion; mapRegion.center = mapView.userLocation.coordinate; mapRegion.span.latitudeDelta = 0.05; mapRegion.span.longitudeDelta = 0.05; 解决方法
我会使用
setCenterCoordinate:animated: 来移动地图焦点.如果您正在加载视图并希望立即将其设置到正确的位置,请设置动画:否,否则,如果要平移地图以平滑居中位置,则设置动画:是
[mapView setCenterCoordinate:location animated:YES]; 当然,这不会改变地图视图的缩放级别.如果要更新缩放级别,则应使用 // 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]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |