本项目是《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. 读书摘要:第七章 闩Suan锁和自旋锁

    摘要: 1.闩锁就像是内存上的锁,随着越来越多的线程参与进来,他们争相访问同一块内存,导致堵塞.2.自旋锁就是闩锁,不同之处是如果访问的内存不可用,它将继续检查轮询一段时间.3.拴锁和自旋锁是我们无法 ...

  2. STM32启动文件选择说明

    图1. STM32F10xxx标准外设库体系结构先说这个问题,大家都知道,我们在选择使用哪些外围的的时候,是去更改从官方模版中拷贝过来的stm32f10x_conf.h文件的27-48行,把我们要用的 ...

  3. android去掉顶部标题栏

    在清单文件(manifest.xml)里面实现 <application> <activity android:name="cn.ui.activity.UserRegAc ...

  4. Java基础の第二弹 基础语法

    Java关键字 •  abstract:表明类或类中的方法是抽象的:•  boolean:基本数据类型之一,布尔类型:•  break:提前跳出一个块:•  byte:基本数据类型之一,字节类型:•  ...

  5. 内存流和null字节

    #include <stdio.h> #include <string.h> int main() { ]={}; FILE* fp = fmemopen(buf,," ...

  6. AMO olap Test C# generate tsql and mdx

    通过AMO访问online的cube,生成等值的TSql和mdx 自动生成等值的TSQL和MDX进行Cube测试.其中难度比较大的部分是拼接TSQL. 暂时不处理calculations,只除理met ...

  7. zookeeper适用场景:如何竞选Master及代码实现

    问题导读:1.如何利用zookeeper保证集群Master可用性和唯一性?2.zookeeper竞选Master包含哪些过程?3.zookeeper竞选Master机制利用了zk哪些特性? 在zoo ...

  8. hyperstart 容器创建流程分析

    hyperstart中运行的pod的核心数据结构如下所示: struct hyper_pod { struct hyper_interface *iface; struct hyper_route * ...

  9. AOJ 739 First Blood

    First Blood Time Limit: 1000 ms   Memory Limit: 64 MBTotal Submission: 152   Submission Accepted: 37 ...

  10. codeforces 711A A. Bus to Udayland(水题)

    题目链接: A. Bus to Udayland 题意: 找一对空位坐下来,水; 思路: AC代码: #include <iostream> #include <cstdio> ...