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);

    }

     



    //移除地图内全部的大头针

    [mapView removeOverlays:mapView.overlays];

    [mapView removeAnnotations:mapView.annotations];



  • 相关阅读:
    14个以春天为主题的网页设计
    使用 CSS3 创建下拉菜单
    视觉灵感:30个漂亮的的网站设计
    Null Object设计模式
    js插件库之图像幻灯片和画廊
    C#读取HTML文件内容写入记事本
    最好的图片水印实现思路
    抽奖系统
    对过万条数据的数据库字段内容批量替换程序
    通用 图片/文字 水印函数
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7084588.html
Copyright © 2011-2022 走看看