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



  • 相关阅读:
    js_mongobd
    window-js-mongodb安装 错误 解决
    Mac-js-mongodb 安装
    PMP笔记-01 PMP各种图比较记忆
    kata qemu
    socat
    kata agent install syslog
    kata rootfs
    defaultKataGuestSharedDir
    kata 9p
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7084588.html
Copyright © 2011-2022 走看看