iphone:MKMapView

简介:

在iphone上实现地图并不难。在Frameworks中加入MapKit.framework,要对mapView做相应的操作时要添加一个outlet,记得#import<MapKit/MapKit.h>即可。

可参考博客 ios利用MKMapView实现简单的地图

 

显示当前自己位置:利用MKMapView显示自己当前位置的地图


加入CoreLocation.framework,

VC遵循

<CLLocationManagerDelegate>

复制代码
 mapView.showsUserLocation=YES; 

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器 
    locationManager.delegate=self;//设置代理 
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别 
    locationManager.distanceFilter=1000.0f;//设置距离筛选器 
    [locationManager startUpdatingLocation];//启动位置管理器 
    MKCoordinateSpan theSpan; 
    //地图的范围 越小越精确 
    theSpan.latitudeDelta=0.05; 
    theSpan.longitudeDelta=0.05; 
    MKCoordinateRegion theRegion; 
    theRegion.center=[[locationManager location] coordinate]; 
    theRegion.span=theSpan; 
    [mapView setRegion:theRegion]; 
    [locationManager release];
复制代码

 

在xcode中设置模拟器的位置,参照:

xcode4.2 模拟器定位 。xcode4.2 添加GPX文件。手工指定位置。 

 

给当前位置加大头针:

使用的是MKMapViewDelegate的mapView:viewForAnnotation:方法

复制代码
  - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
    {
        MKPinAnnotationView *pinView = nil;

            static NSString *defaultPinID = @"com.invasivecode.pin";
            pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
            if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                              initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
            pinView.pinColor = MKPinAnnotationColorRed;
            pinView.canShowCallout = YES;
            pinView.animatesDrop = YES;
             [mapView.userLocation setTitle:@"欧陆经典"];
           [mapView.userLocation setSubtitle:@"vsp"];
         return pinView;
    }
复制代码

参照:http://www.cocoachina.com/iphonedev/sdk/2010/1020/2216.html

 

MKAnnotationView 有一个image属性,应该可以改掉大头针的图形,改为flag?!

 

http://www.helmsmansoft.com/index.php/archives/980罗盘功能

 

 

//设置经纬度

CLLocationCoordinate2D coord = {39.904667,116.408198};

//设置显示范围

MKCoordinateSpan span = MKCoordinateSpanMake(0.4,0.4);

//设置地图显示的中心和范围

MKCoordinateRegion region = MKCoordinateRegionMake(coord,span);

//根据设置的信息进行显示

[mapView setRegion region animated:NO];

[mapView sizeToFit];

   本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/archive/2012/05/14/2499896.html,如需转载请自行联系原作者
相关文章
|
安全
回执签名也能实现无纸化了!碳中和,加油!
或许,从今天开始,可以尝试用“在线回执签名”的方式,来弥补以上不足,简化工作流程。
405 0
|
数据可视化 API 数据库
一个更好的可视化微服务架构的方式
本文讲的是一个更好的可视化微服务架构的方式【编者的话】如何快速地可视化一个微服务架构,本文作者有一个很酷的办法,赶紧来看看吧!
1700 0
|
容器
自己编写的一个数据结构,类似优先级队列
任务 package com.yeepay.sxf.compensation; import java.sql.Date; /** * 任务 * @author sxf * */ public class OrderResponse { /** ...
822 0
计算机中的颜色VI——从色相值到纯色的快速计算
  在上一文中,介绍了“如何快速计算颜色的色相值”,本文介绍从色相值到纯色的计算过程。之前已经介绍,色相值和纯色有着一一对应的关系。先看看传统的计算方法:              从图中计算的过程来看,还是比较繁琐的,再看看之前的纯色色相分布图。
886 0
|
17天前
|
Linux 开发工具 iOS开发
Codex保姆级教程(下载+安装+登录+使用,含所有版本,2026最新)
Codex是OpenAI推出的开源AI编程智能体,本地运行,可理解整个代码库,支持自然语言指令改代码、执行命令、跑测试、修Bug,兼容Win/macOS/Linux。(239字)
7356 56
|
2天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
1341 0