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



  • 相关阅读:
    在Windows环境中使用版本管理工具Git [转]
    poj3630 Phone List **
    UVa10382 Watering Grass **
    软件项目计划书格式 [转]
    POI2001 Ants and the ladybug ***
    RMQ+1/1算法 [转]
    poj3264 Balanced Lineup *
    Windows Server 2003 出现的Service Unavailable怎么办?
    单车环佛山一环
    天凉了,大家多穿衣服
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7084588.html
Copyright © 2011-2022 走看看