CLLocation学习


CLLocation学习

转载自:http://linwwwei.iteye.com/blog/1102555

1:CLLocationDegrees 经纬度

CLLocationDegrees latitude = theLocation.coordinate.latitude;

CLLocationCoordinate2D coordinate = theLocation.coordinate

 

CLLocationDegrees longitude = theLocation.coordinate.longitude;

2:CLLocationAccuracy 精度

有四个值:kCLLocationAccuracyBestForNavigation,kCLLocationAccuracyBest,

kCLLocationAccuracyNearestTenMeters,kCLLocationAccuracyHundredMeters

kCLLocationAccuracyKilometer,kCLLocationAccuracyThreeKilometers

3:MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);//显示比例

 

   MKCoordinateRegion region = MKCoordinateRegionMake(coordinate, span);//定义地图区域

4:MKMapView

 

MapType属性值                 描述

    MKMapTypeStandard           表示标准的街道级地图

    MKMapTypeSatellite          表示卫星图

    MKMapTypeHybird             表示上面两者的混合

5:计算两点间的位置:单位(千米)

[NSString stringWithFormat:@"%0.2f km",[userLocation getDistanceFrom:location]/1000]

6:在处理MKAnnotationView时,都要判断对应annotation是不是MKUserLocation这个显示用户当前位置的蓝点,以避免误 操作。[annotation isKindOfClass:[MKUserLocation class]]

7:- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

这个delegate函数一般会在给MKMapView对象添加 annotations后马上执行,但执行不会马上结束。如果在它完成之前就调用
[mapView viewForAnnotation:someAnnotation];的话,会返回nil的结果,这时对这个返回的nil做任何操作都不会在屏幕上显示

 

8:MKMapView放大缩小时,需要注意的是放大,至少放大2倍以上才会被执行。

MKCoordinateRegion region = mMapView.region;

region.span.latitudeDelta=region.span.latitudeDelta * 0.4;

region.span.longitudeDelta=region.span.longitudeDelta * 0.4;

[mapView setRegion:region animated:YES];(放大)

 

MKCoordinateRegion region = mMapView.region;

region.span.latitudeDelta=region.span.latitudeDelta * 1.3;

region.span.longitudeDelta=region.span.longitudeDelta * 1.3;

[mapView setRegion:region animated:YES];(缩小)

转载于:https://www.cnblogs.com/ls159789/archive/2013/04/15/3022482.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AR实景地图需要使用AR技术和地图API技术进行开发,下面是一个简单的AR实景地图的代码实现: ```swift import UIKit import ARKit import MapKit class ViewController: UIViewController, ARSCNViewDelegate { @IBOutlet weak var sceneView: ARSCNView! var locationManager = CLLocationManager() var userLocation: CLLocation? var annotations = [CLLocationCoordinate2D]() override func viewDidLoad() { super.viewDidLoad() // Set the view's delegate sceneView.delegate = self // Create a new scene let scene = SCNScene() // Set the scene to the view sceneView.scene = scene // Request location authorization locationManager.requestWhenInUseAuthorization() // Set up location manager locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.startUpdatingLocation() // Set up map annotations let annotation1 = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194) let annotation2 = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060) let annotation3 = CLLocationCoordinate2D(latitude: 51.5074, longitude: 0.1278) annotations.append(annotation1) annotations.append(annotation2) annotations.append(annotation3) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // Create a session configuration let configuration = ARWorldTrackingConfiguration() // Run the view's session sceneView.session.run(configuration) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) // Pause the view's session sceneView.session.pause() } func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) { // Check if anchor is a plane guard let planeAnchor = anchor as? ARPlaneAnchor else { return } // Create a plane node let planeNode = SCNNode() planeNode.geometry = SCNPlane(width: CGFloat(planeAnchor.extent.x), height: CGFloat(planeAnchor.extent.z)) planeNode.eulerAngles.x = -.pi / 2 planeNode.opacity = 0.25 // Add plane node to scene node.addChildNode(planeNode) // Add map annotations for annotation in annotations { let annotationNode = SCNNode() annotationNode.geometry = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0) annotationNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red annotationNode.position = getRelativePosition(absoluteCoordinate: annotation, userLocation: userLocation!) node.addChildNode(annotationNode) } } func getRelativePosition(absoluteCoordinate: CLLocationCoordinate2D, userLocation: CLLocation) -> SCNVector3 { let lat1 = userLocation.coordinate.latitude let lon1 = userLocation.coordinate.longitude let lat2 = absoluteCoordinate.latitude let lon2 = absoluteCoordinate.longitude let x = (lon2 - lon1) * cos((lat1 + lat2) / 2) let y = lat2 - lat1 let z = userLocation.distance(from: CLLocation(latitude: lat2, longitude: lon2)) return SCNVector3(x, y, -Float(z)) } } extension ViewController: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { guard let location = locations.last else { return } userLocation = location } } ``` 这个代码实现了在AR场景中显示地图的功能,并且根据用户当前位置和给定的地图标记点,计算出它们在AR场景中的相对位置。但是需要注意的是,这只是一个简单的示例,实际的AR实景地图还需要考虑很多因素,如地图数据的更新、AR场景的稳定性等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值