本项目是《beginning iOS8 programming with swift》中的项目学习笔记==》全部笔记目录

------------------------------------------------------------------------------------------------------------------

1.    打开地图功能:Target-FoodPin-Capabilities-Maps:ON。
2.    在Detail界面的Cell右边拖一个按钮,文字为“Map”,自己设置背景色和字体。
3.    再拖一个控制器到IB,接着拖一个mapKit View进去,连线Map按钮到新的控制器(push),设置identifier为:showMap。
4.    去掉多余的map按钮:增加一个成员变量mapButton并连线,在创建单元格的地方设置是否显示mapButton。
5.    增加一个继承自UIViewController的控制器类MapViewController, import MapKit,设置好成员变量和类的关联:

@IBOutlet weak var mapView: MKMapView!
var restaurant: Restaurant!

6. 实现地址转坐标,并显示到地图上:

override func viewDidLoad() {
super.viewDidLoad() // 将地址字符串转换成坐标
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(restaurant.location, completionHandler: { (placemarks, error) -> Void in
if error != nil {
println(error)
return
} // 取第一个坐标
if placemarks != nil && placemarks.count > {
let placemark = placemarks[] as CLPlacemark // 添加Annotation
let annotation = MKPointAnnotation()
annotation.title = self.restaurant.name
annotation.subtitle = self.restaurant.type
annotation.coordinate = placemark.location.coordinate self.mapView.showAnnotations([annotation], animated: true)
self.mapView.selectAnnotation(annotation, animated: true)
}
})
}

7. 界面跳转时传递restaurant数据:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showMap" {
let destinationController = segue.destinationViewController as MapViewController
destinationController.restaurant = self.restaurant
}
}

8. 给Annotation View加一个图片

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

    // placemark和当前地址都是annotation
if annotation .isKindOfClass(MKUserLocation) {
// 当前地址使用默认的蓝色小点表示
return nil
} // annotation重用
let identifier = "MyPin"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier) // 设置左侧图片
annotationView.canShowCallout = true
let leftIconView = UIImageView(frame: CGRect(x: , y: , width: , height: ))
leftIconView.image = UIImage(named: restaurant.image)
annotationView.leftCalloutAccessoryView = leftIconView
} return annotationView
}

第十章 使用MapKit的更多相关文章

  1. swift项目实战FoodPin目录

    好吧,据说写博客能够找到好工作,那我也来分享一个项目吧! 自己自学iOS开发也有半年多了,现在就来分享一个swift的小项目吧!这个项目的来源是<Beginning iOS8 programmi ...

  2. MapKit/CoreLocation框架 总结

    MapKit/CoreLocation框架 /*英译 core:核心 track:踪迹 current:当前 statellite:卫星 hybird:混合  region:范围 annotation ...

  3. 读《编写可维护的JavaScript》第九、十章总结

    第九章 将配置数据从代码中分离出来 9.2 抽离配置数据 这章比较好理解,也非常常见,作者给的俩个例子就能说明一切: // 将配置数据藏在代码中 function validate(value) { ...

  4. 0526 Sprint1个人总结 & 《构建之法》第八、九、十章

    Sprint1的个人总结: 我是老人组的成员,我们是做一款四则运算训练的软件.然后我是接了界面设计的任务,所以我任务将会是sprint1中相对重一点的一方.我的感觉是,界面要做得充满童趣,毕竟我们的软 ...

  5. Getting Started With Hazelcast 读书笔记(第八章-第十章)

    第八章到第十章就是一些介绍性的描述,吹的就是Hazelcast能使用在各种地方..   第八章 -从外面看 1.Hazelcast做了一个memcache的java实现,方便py和php使用. 2.可 ...

  6. [iOS 利用MapKit和CoreLocation框架打造精简的定位和导航]

    运行效果:            一.利用<CoreLocation/CoreLocation.h>定位 创建变量 CLLocationManager *locationManager , ...

  7. iOS开发——高级篇——地图 MapKit

    一.简介 1.在移动互联网时代,移动app能解决用户的很多生活琐事,比如周边:找餐馆.找KTV.找电影院等等导航:根据用户设定的起点和终点,进行路线规划,并指引用户如何到达 在上述应用中,都用到了定位 ...

  8. Leonbao:MapKit学习笔记

    以下仅作了解, 实际使用以百度地图居多, 因为百度地图有动态路径规划等接口 MapKit学习笔记    原帖: http://www.cocoachina.com/bbs/read.php?tid-6 ...

  9. MapKit 添加大头针

    #import "ViewController.h" #import <MapKit/MapKit.h> #import "MYAnnotation.h&qu ...

随机推荐

  1. Linux Shell 03 条件测试

    条件测试 方式一:在Bash中 test命令和[]是等价的. test命令: if test $n1 -eq $n2 then echo "The two number are equal& ...

  2. ProjectManager Alpha8 - 项目管理器,管理起开发中的项目很方便

    话不多说= = 放几张图了: 文件下载: 32位下载:Package_ProjectManager-1.13.12.exe 64位下载:Package_ProjectManager_x64-1.13. ...

  3. ASP.NET中常用的几个李天平开源公共类LTP.Common,Maticsoft.DBUtility,LtpPageControl (转)

    ASP.NET中常用的几个开源公共类: LTP.Common.dll: 通用函数类库     源码下载Maticsoft.DBUtility.dll 数据访问类库组件     源码下载LtpPageC ...

  4. Python语言100例

    Python版本:python 3.2.2 电脑系统:win7旗舰 实例来源:python菜鸟教程100例 #!/usr/bin/python # -*- coding: UTF-8 -*- impo ...

  5. hadooop2.6 job pending research

    https://hadoop.apache.org/docs/r2.6.0/hadoop-project-dist/hadoop-common/ClusterSetup.html 我使用的是已经运行在 ...

  6. Spring中AOP原理,源码学习笔记

    一.AOP(面向切面编程):通过预编译和运行期动态代理的方式在不改变代码的情况下给程序动态的添加一些功能.利用AOP可以对应用程序的各个部分进行隔离,在Spring中AOP主要用来分离业务逻辑和系统级 ...

  7. tika提取pdf信息异常

    org.apache.tika.sax.WriteOutContentHandler$WriteLimitReachedException: Your document contained more ...

  8. Linux 系统常用命令汇总(五) 磁盘管理

    磁盘管理 命令 选项 注解 示例 df [选项] 显示磁盘空间使用情况 显示磁盘空间是员工情况,以M显示:    df -m -i 使用inodes显示结果 -k(m) 使用KB(MB)显示结果 du ...

  9. [树莓派]安装node环境

    本文并非node的编译安装,据说这要花很长时间,所以一开始我就是拒绝的.本文展示的是如何部署ndoe的编译好的执行文件. node的官网上下载目录里本身就有针对arm的编译好的执行文件.地址在这里:h ...

  10. java解惑 读书笔记

    表达式之谜 >奇数性 当取余操作返回一个非0的结果.他与左操作数具有相同的正负符号. >找零谜题 在需要精确答案的地方,要避免使用float和double.对于货币运算.要使用int,lo ...