1.调用IOS6苹果地图

IOS6中实现这个功能需要使用Map Kit中的MKPlaceMark和MKMapItem两个类,因此我们需要在工程中添加MapKit.framework主要代码如下:

 - (IBAction)geocodeQuery:(id)sender {

     if(_txtQueryKey.text == nil || [_txtQueryKey.text length] == )
{
return;
} CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder geocodeAddressString:_txtQueryKey.text completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"查询记录数:%i",[placemarks count]); if([placemarks count]>)
{
CLPlacemark *placemark = placemarks[]; CLLocationCoordinate2D coordinat = placemark.location.coordinate;
NSDictionary *address = placemark.addressDictionary; MKPlacemark *place = [[MKPlacemark alloc]initWithCoordinate:coordinat addressDictionary:address]; MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place]; [mapItem openInMapsWithLaunchOptions:nil]; //关闭键盘
[_txtQueryKey resignFirstResponder];
}
}];
}

在调用IOS自带的苹果地图应用,openInMapsWithLaunchOptions:方法时MKMapItem类的实例方法,参数时NSDictionary类型,这个参数可以控制地图初始化信息,它包含一些键:

(1)MKlaunchOptionsDirectionsModeKey 设定路线模式,他有两个值MKLaunchOptionsDirectionModeDriving(驾车路线)和 MKLaunchOptionsDirectionsModeWalking(步行路线).

(2)MKLaunchOptionsMapTypeKey 设定地图类型。

(3)MKLaunchOptionsMapCenterKey设定地图中心点。

(4)MKLaunchOptionsMapSpanKey设置地图跨度。

(5)MKLaunchOptionsShowsTrafficKey设置交通状况。

例如,可以使用下面的代码在地图上设置行车路线:

NSDictionary *options=[[NSDictionary alloc]initwithObjectsAndKeys:MKLaunchOptionsDirectionsModeDriving,MkLaunchOptionsDirectionsModeKey,nil];

MKMapItem *mapItem = [[MKMapItem alloc] initwithPlacemark:place];

[mapItem openInMapsWithLaunchOptions:options];

设置行车路线后,地图上标注出路线,默认情况下起点时当前位置,这个位置是通过定位服务获得的。

如果有多个点需要标注,我们可以使用MKMapItem的类方法:

+(BOOL)openMapsWithItems:(NSArray *)mapItems launchOptions:(NSDictionary *)launchOptions

其中参数mapItems是标注点的集合,launchOptions是启动参数。如果想使用这个方法,则上面的例子可以修改如下:

 - (IBAction)geocodeQuery:(id)sender {

     if(_txtQueryKey.text == nil || [_txtQueryKey.text length] == )
{
return;
} CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder geocodeAddressString:_txtQueryKey.text completionHandler:^(NSArray *placemarks, NSError *error) { NSMutableArray *array = [NSMutableArray new]; for (int i=; i<[placemarks count]; i++) {
CLPlacemark *placemark = placemarks[i]; CLLocationCoordinate2D coordinat = placemark.location.coordinate;
NSDictionary *address = placemark.addressDictionary; MKPlacemark *place = [[MKPlacemark alloc]initWithCoordinate:coordinat addressDictionary:address]; MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place]; [array addObject:mapItem];
//关闭键盘
[_txtQueryKey resignFirstResponder];
} if([array count]>)
{
[MKMapItem openMapsWithItems:array launchOptions:nil];
}
}];
}

2.调用谷歌web地图

也可以借助谷歌的web地图API进行开发地图应用程序,但这里涉及的技术都是web技术了,而非本地技术,谷歌提供的地图查询url形式如下:

 - (IBAction)geocodeQuery:(id)sender {

     if(_txtQueryKay.text == nil || [_txtQueryKay.text length] == )
{
return;
} CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder geocodeAddressString:_txtQueryKay.text completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"查询记录数:%i",[placemarks count]); if([placemarks count]>)
{
CLPlacemark *placemark = placemarks[]; CLLocationCoordinate2D coordinate = placemark.location.coordinate; NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/map?q=%f, %f",coordinate.latitude,coordinate.longitude]; NSURL *url= [NSURL URLWithString:urlString]; [[UIApplication sharedApplication] openURL:url]; //关闭键盘
[_txtQueryKay resignFirstResponder];
}
}];
}

IOS 使用程序外地图(IOS Map and google Map)的更多相关文章

  1. iOS开发——程序员必备&iOS安装包的三种格式 deb、ipa 和 pxl的解释和说明

    iOS安装包的三种格式 deb.ipa 和 pxl的解释和说明 目前 iOS 平台上常见的安装包有三种,deb.ipa 和 pxl.转自链接:http://fanlb.blogbus.com/logs ...

  2. Delphi for iOS开发指南(3):创建一个FireMonkey iOS应用程序

    http://cache.baiducontent.com/c?m=9d78d513d9d431a94f9d92697d60c015134381132ba1d0020fa48449e3732b4b50 ...

  3. 使用Visual Studio开发跨平台的iOS应用程序

    [原文发表地址]Developing cross-platform iOS application using Visual Studio [原文发表时间]2015/6/4 C ++是一种流行的高级编 ...

  4. 2021 年 iOS 应用程序开发七种最佳语言

    移动应用程序现在几乎是每个在线业务的必备品.最新的 StatCounter 数据显示,多达56% 的在线连接是通过移动设备建立的,这使它们高于平板电脑和计算机.更重要的是,同一个消息来源说,其中27% ...

  5. 房产地图google map的初步应用点滴.2)(转)

    房产地图google map的初步应用点滴.1)房产地图google map的初步应用点滴.2)房产地图google map的初步应用点滴.3) 房产地图google map的初步应用点滴.4) 本来 ...

  6. (6)Xamarin.android google map v2

    原文 Xamarin.android google map v2 Google Map v1已经在2013年的3月开始停止支持了,目前若要在你的Android手机上使用到Google Map,就必须要 ...

  7. Google Map和桌面组件 Android开发教程

    本文节选于机械工业出版社推出的<Android应用开发揭秘>一 书,作者为杨丰盛.本书内容全面,详细讲解了Android框架.Android组件.用户界面开发.游戏开发.数据存储.多媒体开 ...

  8. Google Map API v2 步步为营 (二)----- Location

    接上篇. 改造一下MapsActivity: public class MapsActivity extends Activity implements LocationListener, InfoW ...

  9. iOS开发---集成百度地图完善版

    一.成为百度的开发者.创建应用 http://developer.baidu.com/map/index.php?title=首页 (鼠标移向 然后选择你的项目需要的功能 你可以在里面了解到你想要使用 ...

随机推荐

  1. golang之interface(接口)与 reflect 机制

    一.概述 什么是interface,简单的说,interface是一组method的组合,通过interface来定义对象的一组行为: interface类型定义了一组方法,如果某个对象实现了某个接口 ...

  2. 快照(Snapshot)

    一.定义: SNIA(存储网络行业协会)对快照(Snapshot)的定义是:关于指定数据集合的一个完全可用拷贝,该拷贝包括相应数据在某个时间点(拷贝开始的时间点)的映像.快照可以是其所表示的数据的一个 ...

  3. Powerdesigner逆向工程从sql server数据库生成pdm

    第一步:打开"控制面板"中的"管理工具" 第二步:点击"管理工具"然后双击"数据源(odbc)" 第三步:打开之后,点击 ...

  4. javascript中数组排序

    在javascript中Array类中提供了一个可以为数组排序的方法Array.sort(): 但此方法排序方式是按照unicode码进行的排序,若将整数型加入到数组元素中, 排出的结果往往达不到我们 ...

  5. WCF创建到使用到发布

    1,在VS里面新建一个类库项目 2,向类库项目里添加WCF服务文件 3.按照WCF约束规范编写接口和实现类 using System; using System.Collections.Generic ...

  6. 一个JAVA代码

    public class HelloJava { public static void main(String[] args) { System.out.println("这"); ...

  7. Hibernate学习之Hibernate流程

    Hibernate的核心组件 在基于MVC设计模式的JAVA WEB应用中,Hibernate可以作为模型层/数据访问层.它通过配置文件(hibernate.properties或hibernate. ...

  8. 戏说Java多线程

    戏说Java多线程. package com.cmp.chengfu.app.jdk6.desktop; import java.awt.Desktop; import java.io.File; i ...

  9. Android开发笔记--hello world 和目录结构

    原文:Android开发笔记--hello world 和目录结构 每接触一个新东西 都有一个hello world的例子. 1.新建项目 2.配置AVD AVD 没有要新建个,如果不能创建 运行SD ...

  10. HDU 11488 Hyper Prefix Sets (字符串-Trie树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...