zoukankan      html  css  js  c++  java
  • IOS 地图移动中心点获取

    MKMap显示地图后,如果用户移动了地图,自己定义的数据就需要刷新了,所以这个时候,中心点的经纬度就比较重要了。

    本文演示如何获取经纬度

    在MKMapViewDelegate里有个方法

    - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated  

    这个方法就是在Map移动 后执行,所以我们可以在这里获取移动后地图中心点的经纬度了。

    复制代码

     - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {

        MKCoordinateRegion region;
        CLLocationCoordinate2D centerCoordinate = mapView.region.center;
        region.center= centerCoordinate;
        
        NSLog(@" regionDidChangeAnimated %f,%f",centerCoordinate.latitude, centerCoordinate.longitude);
    }
    复制代码

    同样有个问题,如何获取用户点击地图某个区域的经纬度呢?

    方法如下

     在ViewDidLoad里添加tabGuesture

        
        UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPress:)];
        [self.mapView addGestureRecognizer:mTap];

        [mTap release]; 

    复制代码
    -(void)tapPress:(UIGestureRecognizer*)gestureRecognizer
    {
        
        CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView ];
        CLLocationCoordinate2D touchMapCoordinate =
        [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView ];
        
        NSLog(@"%f %f",touchMapCoordinate.latitude, touchMapCoordinate.longitude);
    }
  • 相关阅读:
    php
    php数据排序---array_multisort
    IOS 线程描述
    IOS 进程描述
    IOS 强指针(strong)和弱指针(weak)
    IOS autosizing(设置控件的固定位置大小)
    IOS UIActivityIndicatorView动画
    IOS UIImageView的帧动画
    IOS Block动画
    IOS UIView动画(封装动画)
  • 原文地址:https://www.cnblogs.com/sunfuyou/p/6906797.html
Copyright © 2011-2022 走看看