百度地图插件代码autorotation是什么意思

【地图】使用高德map显示map轨迹 - 互联网当前位置:& &&&【地图】使用高德map显示map轨迹【地图】使用高德map显示map轨迹&&网友分享于:&&浏览:16次【map】使用高德地图显示地图轨迹
&!DOCTYPE HTML&
##全屏显示
&style type="text/css"&
html { height: 100%}
body {height:100%;margin:0padding:0px}
&meta http-equiv="Content-Type" content="text/ charset=utf-8"&
&title&轨迹回放&/title&
&link rel="stylesheet" type="text/css" src="./map.css" /&
&script language="javascript" src="/maps?v=1.3&key=您申请的key值"&&/script&
&script language="javascript"&
//初始化地图对象,加载地图
function mapInit(){
mapObj = new AMap.Map("iCenter",{
zooms:[7,17],
//二维地图显示视口
view: new AMap.View2D({
center:new AMap.LngLat(116..90923),//地图中心点
zoom:13 //地图显示的缩放级别
continuousZoomEnable:false
AMap.event.addListener(mapObj,"complete",completeEventHandler);
//地图图块加载完毕后执行函数
function completeEventHandler(){
marker = new AMap.Marker({
map:mapObj,
//draggable:true, //是否可拖动
position:new AMap.LngLat(116..90923),//基点位置
offset:new AMap.Pixel(-26,-13), //相对于基点的位置
autoRotation:true
marker = new AMap.Marker({
map:mapObj,
//draggable:true, //是否可拖动
position:new AMap.LngLat(116..909270),//基点位置
offset:new AMap.Pixel(-26,-13), //相对于基点的位置
autoRotation:true
marker = new AMap.Marker({
map:mapObj,
//draggable:true, //是否可拖动
position:new AMap.LngLat(116..909320),//基点位置
offset:new AMap.Pixel(-26,-13), //相对于基点的位置
autoRotation:true
marker = new AMap.Marker({
map:mapObj,
//draggable:true, //是否可拖动
position:new AMap.LngLat(116..961329),//基点位置
offset:new AMap.Pixel(-26,-13), //相对于基点的位置
autoRotation:true
marker = new AMap.Marker({
map:mapObj,
//draggable:true, //是否可拖动
position:new AMap.LngLat(116..960287),//基点位置
offset:new AMap.Pixel(-26,-13), //相对于基点的位置
autoRotation:true
var lngX = 116.397428;
var latY = 39.90923;
lineArr = new Array();
lineArr.push(new AMap.LngLat(lngX,latY));
lineArr.push(new AMap.LngLat(116..909270));
lineArr.push(new AMap.LngLat(116..909320));
lineArr.push(new AMap.LngLat(116..961329));
lineArr.push(new AMap.LngLat(116..960287));
//绘制轨迹
var polyline = new AMap.Polyline({
map:mapObj,
path:lineArr,
strokeColor:"#00A",//线颜色
strokeOpacity:1,//线透明度
strokeWeight:3,//线宽
strokeStyle:"solid"//线样式
mapObj.setFitView();
#iCenter{}
&body onLoad="mapInit()" width:100%;height:100%;&
&div class="iCenter" id="iCenter" &&/div&
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有高德地图jsapi调用 - 推酷
高德地图jsapi调用
今天公司项目要做一个基于地图的位置展示,在网上找了下,发现高德地图开放api能满足功能,现对其应用做一下简单的记录。
1.首先在高德开发平台上注册,简单填写相关信息后,可以获得key,拿到key后可以调用高德地图api的相关接口。
2.在调用api的相关页面引入高德api,eg:
&script type=&text/javascript&
src=&/maps?v=1.3&key=youKey&&
3.根据初始位置创建地图实例,eg:
var position = new AMap.LngLat(x, y);
//创建地图实例
mapObj = new AMap.Map(&container&, {
view : new AMap.View2D({//创建地图二维视口
center : position,//创建中心点坐标
zoom : 10, //设置地图缩放级别
rotation : 0
//设置地图旋转角度
lang : &zh_cn&//设置地图语言类型,默认:中文简体
4.在页面上进行初始化,一般在body上eg:
&body onload=&initialize('121.476753','31.224349')&&
地图显示位置在div中定义:
&div id=&container& style=&width:85%; height:500margin:0;&&&/div&
需要说明的是,显示位置放在table中会有显示不出来的问题,推荐放在div中进行位置改变。
5.在地图特定位置显示信息,eg:
var info = [];
info.push(&&div&&div&&img width='67px' height='16px' style=\&float:\& src=\&${ctx}/images/main/logo.png \&/&&/div& &);
info.push(&&div style=\&padding:0px 0px 0px 4\&&&b&上海北斗&/b&&);
info.push(&x坐标:&+x);
info.push(&y坐标:&+y);
info.push(&地址 : 上海市虹口区欧阳路法兰桥创意园196号&/div&&/div&&);
infoWindow = Window({
content:info.join(&&br/&&) //使用默认信息窗体框样式,显示信息内容
infoWindow.open(mapObj,new AMap.LngLat(x,y));
6.自定义图标点图标
//创建点图标
var marker = new AMap.Marker({
icon:&/images/marker_sprite.png&,
position:new AMap.LngLat(x,y),
offset:new AMap.Pixel(-26,-13),
autoRotation:true
marker.setMap(mapObj); //在地图上添加点
7.上面是一些简单的api调用,详细的高德开放平台都有提供相应的api,可具体情况具体对待。
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致As these seeds fall to the ground, their wing causes them to swirl and spin in a process called autorotation, similar to man-made helicopters.
当这些种子降落到地面的过程中,它们的翅膀会使得种子旋转并产生自转,与人造的直升机功能相仿。
“We want to take advantage of the autorotation mode since it doesn't require power for flight,” he said. “If we can find a vertical column of air, it can stay aloft indefinitely.
“因为它不需要飞行的电力,我们希望能发挥自旋模式的优点,”他说,“如果我们可以找到竖直而行的空气,它可以永远停留在空中。
However, through free-fall testing, the researchers could quantitatively measure the samara’s flight dynamics and use this information to control the samara’s autorotation and flight path.
然而,通过自由落体测试,研究者可以量化的测量翅果的飞行动力并且用得到的信息数据来控制翅果的自旋和飞行轨迹。
The samara-inspired autorotation process has several advantages compared to other small-scale aircraft that perform vertical take-off and landing.
受翅果启发的自旋过程比起其他小尺寸飞行器在起飞和着陆的表现上,有几个好处。
Since then, several other single-winged rotating aircraft have been developed, but none of these designs has used autorotation or been based on the samara.
自那以后,数种单翼旋转飞行器被发明,但没有一个设计使用了自旋或是基于翅果。
The phantom autorotation function lets you, no matter how to grasp the camera also to be able to glance over to the limit the good demonstration normally.
影像自动旋转功能让您不论如何手持相机也能正常地浏览到极佳的显示。
The landing of a helicopter in autorotation is formulated as a nonlinear optimal control problem.
本文将直升机的自转着陆过程定义为一个非线性的最优控制问题。
Starting from an altitude of no less than twenty (20) meters and on a heading parallel to the flight line, with the helicopter inverted and to the pilot right, start your Autorotation.
机头保持与航道平行,且高度不得低于20公尺,直升机保持倒飞姿态,向操控者的右侧开始执行熄火降落。
During the Autorotation, pirouette the helicopter a minimum of three (3) times.
执行熄火降落的过程中,机体至少需自旋3圈。
The structure of a banana-shaped submarine gate was used to inject, and the autorotation mode was used to demould.
采用香蕉形状的曲线形潜伏式浇口结构形式和自动旋转方式分别进行进浇和脱模。
Clutch and overspeed provision during autorotation .
离合器和超速期间提供自转。
The autorotation characteristics of helicopter are directly related to its safety and reliability.
直升机自转特性的好坏,直接关系到该型机安全性和可靠性。
The test model was made and an experiment was done to verify the prediction of the autorotation state characteristics for a high-speed rotorcraft scheme.
针对某一高速直升机方案的自转状态,本文设计和建设了试验模型和试验设备,进行了相应的实验研究。
This article is introduced the concept of helicopter autorotation and analyzed the energy conversion during autorotation landing.
介绍了直升机自转下滑的概念,对自转下滑着陆过程中的能量转换进行了分析。
A three-dimensional rigid body model is used to study the landing of a helicopter in autorotation.
首先,建立了一个描述直升机自转着陆飞行动力学特性的三维刚性体模型。
This paper describes the contents including the helicopter autorotation coming into lag time, autorotation landing, flight theory determined by flight quality, flight method and pilot technique.
本文从试飞员的角度系统讲述了直升机自转进入滞后时间、自转着陆及飞行品质确定的试飞原理,试飞方法及驾驶技术等内容。
Objective To explore the normal values of vestibular autorotation test(VAT) in young people.
目的了解健康青年人的前庭自旋转试验(VAT)的正常值。
The helicopter does not have to be pirouetting when the Autorotation starts.
在执行熄火降落的动作之前,机体不须保持自旋。
It is composed of a circular autorotation crawling mechanism, a CCD camera, a movement control card based on DSP and a high-resolution image acquisition card, and so on.
该系统由环形自转式运动机构、CCD摄像机以及基于DSP的运动控制卡和高分辨率的图像采集卡等组成。
We also discuss the respects of the formation of satellites and the earth's autorotation.
本文还分析了小卫星编队立体队形及地球自转等因素下的动目标测速去模糊。
The main structure and the rotating mechanism of autorotation container were introduced.
介绍了数控回转立体库的主要结构及其回转机构的原理。
Autorotation is material together with the Can doing the axial (axis:O1-O2) rotation.
物料随容器绕容器轴线(O1—O2)旋转,称为自转;
Gliding descent in autorotation is a maneuver used by helicopter pilots in case of engine failure.
当直升机的发动机失效后,自转下滑就成为驾驶员实现安全着陆的唯一有效手段,这需要熟练的驾驶技术。
By combining with the machining needs of parallel machine tools, the working space and the law along with the variation of its autorotation angle were studied.
结合并联机床的加工要求,研究了工作空间及其随自转角的变化规律。
This paper discussed the formation of water scaling and the influence of water scaling in the operation of steam turbine; and introduced the principle of autorotation plastic twisted tapes.
论述了凝汽器内水垢的形成和水垢对汽轮机运行的影响,介绍了自转塑料纽带的工作原理及热电企业运用塑料纽带自动旋转达到除垢防垢、强化传热、节能降耗,最后提出了应用建。
The utility model relates to an autorotation silent electricity-saving coil, used on the AC contactor in the low-voltage controlling circuit, realizing the silent electricity-saving running.
本实用新型涉及的是一种自转无声节电线圈,用于低压控制电路中的交流接触器上,并实现无声节电运行。
ABSTRACT:Objective To explore the normal values of vestibular autorotation test (VAT) in young people.
摘要:目的了解健康青年人的前庭自旋转试验(VAT)的正常值。
This machine adopts in horizontal style anddouble thimble design . Using the grinding wheel polishing by hand whth autorotation. It features simple operation, high stability and easy installation.
变频磨光机采用卧式结构和双顶针座设计,它是自动旋转,手动磨光,具有操作简单,稳定性高及安装方便。
The utility model relates to a bat printing machine adjustable magnetic force autorotation sealed ink cup.
一种移印机可调磁力自转密封油墨杯。
The utility model relates to a bat printing machine adjustable magnetic force autorotation sealed ink cup.
一种移印机可调磁力自转密封油墨杯。
$firstVoiceSent
- 来自原声例句
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!Lost in Nowhereland with no Internet connection as far as you can see? As always, Google Maps can help you find your way back, as long as you have an iOS or an Android device, even if you are offline. Google recently added a feature to Google Maps, which lets you save maps to your phone.Yes, you can now check maps even when there is no Internet connection. The downside is that you will not have access to route information, addresses, navigation, traffic, and a host of other data that require an Internet connection. However, having map data for reference might just save you a lot of time. Here's how to use this nifty feature on iOS and Android. The steps are identical for both platforms.&What you need to use this featureYou're going to need an Android or iOS device. Unfortunately, this feature isn't available on other platforms. Google Maps version 3, which was released last week on iOS, added support for offline maps. Android users, be sure to update to Google Maps version 8 before following the steps listed below.(Also see: )How to save maps offline?1. To use this feature, first sign in to your Google account to use this feature.2. Type "OK Maps" in the search bar and hit the search button. A dialog at the top of the map asks "Save this map?" with a Save button at the bottom of the screen.3. At this point, you can zoom in or out, and move the map, to select the area you want to save. Everything that is on-screen gets downloaded, so if you zoom out to save the entire Delhi area, for example, then you can later zoom in to see the individual localities and streets.4. Once you've selected the area, tap the Save button at the bottom of the screen. A dialogue box pops up and you are asked to enter a name for the map. Just enter a name and tap on Save.5. Accessing offline maps is easy. Just tap the 'person' icon, which is next to the directions icon on the search bar. This will take you to your profile. Scroll to the bottom to see your saved maps. You can rename saved maps in case you plan to save more than one.There are certain limitations to saving offline maps. Zoom out too far and you will see an error saying that the map area can't be saved because it is too large. We were able to save almost all of Delhi, but Google Maps deemed the area "too large" when we tried to save National Capital Region (NCR).There's nothing stopping you from saving multiple maps to cover a large area, in case you're worried about that. Another limitation is that map data is available only for 30 days. You'll have to download maps again after this.The good thing is that the saved map of Delhi occupied just 9.9 MB of space on our phones. That's good news for those who are running low on storage space.Have you ever saved Google Maps and used them offline? Ever been knocked offline, lost and wished you had access to offline maps? Tell us about it in the comments section below
For the latest
and , follow Gadgets 360 on , , and subscribe to our .
Fields marked with * are mandatory&&&&&&&&&&&&&&&&&&
posts - 17,comments - 17,trackbacks - 0
今天要讲的是设备的位置,包括如何找到设备的位置和如何在地图上显示位置。
Core Location
Core Location不是一个UI的东西,没有用户界面,它只是关于找到该设备的位置。新设备有很多定位装置,比如磁力计、加速度计、全球定位系统(GPS),各种无线,各种能找出你在哪里的东西。Core Location的基本对象是一个CLLocation,CL是Core Location库的前缀,location是基本对象。CLLocation里的properties:
@properties: coordinate, altitude, horizontal/verticalAccuracy, timestamp, speed, course
关于这个位置读数的精度,会谈到时间戳(timestamp),就是这个位置何时被记录。speed,移动的速度有多快,通过GPS坐标的瞬时读数判断。course,类似移动的航行。最重要的是coordinate,它告诉你这个CLLocation在哪里。
coordinate是一个C结构体,只有latitude(经度)和longitude(纬度):
@property (readonly) CLLocationCoordinate2D
CLLocationD
//a double
CLLocationD
//a double
} CLLocationCoordinate2D;@property (readonly) CLLocationD // meters
CLLocationDegrees基本上是double,浮点数。altitude(海拔)单位是米,可以得到海拔的高度。
coordinate的latitude和longitude有多精确?CLLocation有一对properties:
@property (readonly) CLLocationAccuracy horizontalA
// in meters
@property (readonly) CLLocationAccuracy verticalA
// in meters
它告诉你漂移量是多少,单位是米。通常不会把它们当做数值来看,会更多地看这些预定义的值,如AccuracyBestForNavigation,它将不断更新GPS。GPS可以测量垂直。
kCLLocationAccuracyNearestTenMeters就基本是你在的位置;kCLLocationAccuracyHundredMeters就是你在这一区域的某处;kCLLocationAccuracyKilometer和kCLLocationAccuracyThreeKilometers都是采用基站的方式,精度非常粗糙。
最好的是用不断更新的GPS(精度最高,耗电量最大),次好的是用WiFi(设备可以发现周围的WiFi热点和信号有多强,并通过查看互联网上的一个数据库来找出你在哪里),第三个也是最不准确的是基站(最不准确的,几乎不耗电)。所以是根据你的app需要什么精度来选择。
速度、航向、时间戳,这些都是一种即时测量,比如speed只计算最后一定数量的GPS位置,course就是航向,所有这些API都是抽象的,它只是根据你的设备来向你汇报最佳信息。
怎么得到CLLocation,这些Core Location里的位置对象?几乎总是通过另一个对象CLLocationManager获取。
在ios 5中要注意的一件重要的事情是,你可以模拟你的位置,当你在模拟器上使用这个运行时才出现的菜单,基本上可以在地球上随便挑个地方作为你的位置,甚至可以有自己的GPX文件,它像个简单的XML格式,里面编码了一堆经度和纬度,甚至可以模拟移动之类的:
有四件事与CLLocationManager有关,四个都要做:
第一个,是你要检查有什么硬件可用;
第二个,你要创建这些CLLocationManagers之一,并设置自己为delegate,因为CLLocationManager将要使用delegate来进行更新;
第三个,你要配置这个manager,你想要什么样的位置更新、航行或仅仅是位置移动,有各种不同的定位监测,它不是只能告诉我我在哪里, 它有相当的灵活性,当你设置好后要进行下一步;
第四个,就是你要开始监测,当你启动它的监测,它会根据你的配置来给delegate发消息。
有哪些基于位置的监控?有基于精度的持续更新,这意味着你设置了精度,然后在这个精度等级下的移动都会得到持续的更新;再有就是只有发生显著变化时才更新;还有基于区域的更新,定义一个地球上的区域,当人进入该地区时,你会得到更新;当然还有航行监测,它只会在设备指向不同的方向时进行报告。
第一个步骤是检查,看看你的硬件可以做什么:
+(BOOL)locationServicesE //has the user enabled location monitoring in Settings?
+(BOOL)headingA
// can this hardware provide heading info (compass)?
+(BOOL)significantLocationChangeMonitoringA //only if device has cellular?
+(BOOL)regionMonitoringA//only certain iOS4 devices +(BOOL)regionMonitoringE//by the user in Settings
你必须要检查一些事情,比如locationServicesEnabled,因为当你请求这些东西的时候,系统会弹出警告说这个app要使用你的位置,如果用户选择no,定位服务不会开启。甚至要检查,看看这些东西是否可行,并非所有的设备可以做这些事情。
当系统提示你的app要使用位置服务的时候,它会用这个字符串,CLLocationManager里的Purpose string:
@property (copy) NSString *
这就是提示的内容,所以这会用来解释为什么这个app要使用你的位置服务,这样的目的可能是用你的GPS位置来标记你的图片。你设置了CLLocationManager里的Purpose string,当你开始监控,如果系统询问用户,将会使用此字符串。如果终端用户允许你使用定位服务,几乎肯定可以得到他们的GPS定位。
在苹果公司有很多政策文件,它们建议你如何做用户界面,甚至是在App Store审核的时候的一些强制条款。
一旦检查过了有什么硬件可用,现在你就可以从CLLocationManager获取信息了,你通常不会主动获取,通常你可以设置它的delegate,然后设置你想要的精度,然后你还可以设置distanceFilter,只有离开上个更新点一定距离才进行更新:
@property CLLocationAccuracy desiredA //always set this as low as possible
@property CLLocationDistance distanceF
你设置了这些,然后你只需要调用CLLocationManager的startUpdatingLocation,它将开始向你的delegate发消息:
- (void)startUpdatingL
- (void)stopUpdatingL
最主要的方法是:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldL
它会向你发送一个新的CLLocation对象,也将发送给你上次那个,这样你就可以跟踪用户在做什么。
Heading monitoring基本上和location monitoring是一样的,只是监测航向。当它给你一个航向,heading长什么样子?就像CLLocation一样,是CLHeading,CLHeading有magneticHeading(磁场航向)和trueHeading(真实航向),如果位置服务被关闭了,GPS和wifi所有这一切都是通过磁力计的,都是magneticHeading。位置服务必须打开,否则无法得到trueHeading,只能得到magneticHeading。
磁力计会让你把手机做8字移动,这样它就能测量磁力计收到的电磁干扰,这是由ios自动完成。可以通过在以下方法里返回NO来阻止它:
- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)
你不应该忽略此delegate方法,不能得到很好的航向信息,就会得到error,就会知道发生了什么事:
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)
这是基于精度的更新,还有其他各种位置监测,一个被称为Significant location change monitoring(显著位置变化监测),它只监视大的变化,酷的是你的app甚至不用运行,一旦你的app注册以后,你就会开始接收这些显著的位置变化。如果app因为Significant location change而被运行,你会得到appdelegate.m中的application:didFinishLaunchingWithOptions:方法。如果你打开这个Significant location change,然后Significant location change发生了,并且app在后台,app仍然会得到其delegate方法,app会得到唤醒。
类似的,还有基于区域的东西,指定一个区域,当进入或离开该区域,你都会得到更新。同样的,没有运行也会得到这些更新。
这是一个不同的framework,这是你如何使用这种谷歌地图技术来图形地显示位置。
Map Kit里的主要类是MKMapView,它只是一个UIView,用来显示地图。在地图上,MKMapView有一个非常重要的property称为annotations,它是一个实现MKAnnotation protocol的对象的NSArray,该protocol仅仅是一个coordinate、一个title和一个subtitle。annotations使用MKAnnotationView来显示在地图上,它们以红色的pins的形式出现,annotations还可以有一个callout,当你点击pin,一种灰色的矩形会出现就是callout,并展示了一些信息,比如它要同时呈现title和subtitle,也可以有左右callout accessory。
要如何创建一个MapView?通常将它从对象库里拖到你的东西里面。还有这个property,annotations的数组:
@property (readonly) NSArray * // contains id &MKAnnotation& objects
这是一个id&MKAnnotation&对象的数组,它们可以是任何类对象,但它们必须要实现MKAnnotation protocol。所以这不是delegation,这是一个不同的protocol使用,这仅是定义一个对象可以做什么。
MKAnnotation protocol里有什么?其中之一是required的,就是coordinate,这只是一个CLLocationCoordinate2D;其他两个是optional:title和subtitle。annotation里的对象只要实现这几个。
注意annotations是只读的,可以通过以下方法来添加annotations或删除annotations:
- (void)addAnnotation:(id &MKAnnotation&)
- (void)addAnnotations:(NSArray *)
- (void)removeAnnotation:(id &MKAnnotation&)
- (void)removeAnnotations:(NSArray *)
通常一开始你就把你的annotations都放进去,因为MapView会像TableView那样重用这些pins。如果把它们都放进去,就会知道所有pins的位置,可以更高效的知道当前哪些地方需要pins。
annotations在地图上的外观:这些pins,这些MKPinAnnotationView,是在Map Kit里的默认的view,它有几个property,比如可以设置pins的颜色。也可以创建自己的MKAnnotationView子类,基础类是image,MKPinAnnotationView就是设置该image为pin,不要把MKAnnotation使用的image如这个pin image和callout里的image混淆了。
当你点击一个annotation view会发生什么呢?callout会出来。如何控制callout的内容,在MapView里有个非常重要的delegate,设置它的delegate就会得到这个消息:
- (void)mapView:(MKMapView *)sender didSelectAnnotationView:(MKAnnotationView *)aV
当annotation被点击的时候它会发消息给你。记住,annotation view知道哪个annotation正在被浏览,所以也就可以得到被点击的那个annotation。
如何创建这些MKAnnotationViews?如果什么都不做,会得到pin,当你点击pin,会得到一个带有title和subtitle的callout。如果你想控制callout的内容或外观,你可以实现MapView的delegate方法:
- (MKAnnotationView *)mapView:(MKMapView *)sender
viewForAnnotation:(id &MKAnnotation&)annotation
MKAnnotationView *aView = [sender dequeueReusableAnnotationViewWithIdentifier:IDENT];
if (!aView) {
aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:IDENT];
// set canShowCallout to YES and build aView&s callout accessory views here
aView.annotation = // yes, this happens twice if no dequeue
// maybe load up accessory views here (if not too expensive)?
// or reset them and wait until mapView:didSelectAnnotationView: to load actual data
这和tableView的cellForRowAtIndexPath非常相似。每次要在地图上显示一个特定的annotation的时候,它会被调用,它要调用这个来得到要显示的veiw。要让canShowCallout等于YES,否则点击的时候就不会得到callout。不管aView是被创建或被出队,都要设置annotations。
如果设置了callout的左侧或右侧为一个control,就像一个按钮,当有人点击它,就会调用MKMapViewDelegate的方法:
- (void)mapView:(MKMapView *)sender
annotationView:(MKAnnotationView *)aView
calloutAccessoryControlTapped:(UIControl *)
因此这样就不用再建target action,这是一个callout view内部的按钮。不要把这个方法和didSelectAnnotationView弄混了,这是点击在callout里的按钮上,而后者是点击在pin上。
通常直到didSelectAnnotationView发生了,才显示callout里的左右测:
- (void)mapView:(MKMapView *)sender didSelectAnnotationView:(MKAnnotationView *)aView {
if ([aView.leftCalloutAccessoryView isKindOfClass:[UIImageView class]]) {
UIImageView *imageView = (UIImageView *)aView.leftCalloutAccessoryV
imageView.image=...; //if you do this in a GCD queue,be careful,views are reused!
不希望在viewForAnnotation里加载所有callout的图片,要在didSelectAnnotationView里才加载。如果正在使用GCD加载Flickr的图像的缩略图,用了另一个线程,线程返回时要小心,因为pins是被重用的。pins可能在某个地方被点击了,然后用户滚动到其他地方了,当Flickr的东西下载回来的时候,所选择的annotation view可能早就不在了,所以返回的时候得做一些检查,当Flickr的图像回来的时候得确保界面还是原来的样子。所以要做个测试,以确保在写image=之前一切仍然是老样子。
配置display type:用MKMapType mapType来指定显示卫星模式或街道模式和卫星模式的混合体。还可以用一个特殊的pin显示用户当前的位置,也可以在地图上缩放和滚动:
@property MKMapType mapT
@property BOOL showsUserL
@property (readonly) BOOL isUserLocationV
@property (readonly) MKUserLocation *userL
@property BOOL zoomE
@property BOOL scrollE
可以通过设置MapView的region property来控制显示的区域,它只是个CLLocationCoordinate2D,这是经度、纬度和一个跨度,span(跨度)就是纬度上有多远,center就是其中心,region有一定的跨度。当你设置了region,地图将可以滚动和放大显示该区域,也可以只设置中心点,这样就只能滚动不能缩放。
@property MKCoordinateR
typedef struct {
CLLocationCoordinate2D
MKCoordinateS
} MKCoordinateR
typedef struct {
CLLocationDegrees latitudeD
CLLocationDegrees longitudeD
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL) // animate
开始加载地图时,delegate会得到通知。记住,整个世界、卫星图像都不在手机上,所以当你左右滚动,它从Google Map上下载地图信息,因此它是一块一块显示的。这将告诉你什么时候开始向网络获取更多,和何时它完成加载。
Remember that the maps are downloaded from Google earth.
- (void)mapViewWillStartLoadingMap:(MKMapView *)
- (void)mapViewDidFinishLoadingMap:(MKMapView *)
- (void)mapViewDidFailLoadingMap:(MKMapView *)sender withError:(NSError *)
它和annotations非常相似,不同的地方只是绘制图像、点击一下,可以绘制Overlays。通常情况下,Overlays更大,它们不是在一个点上,它们将是Overlays的重叠,你要实际绘制它。
设置Overlays的方法和annotations一样:
- (void)addOverlay:(id &MKOverlay&)
// also addOverlays:(NSArray *)
- (void)removeOverlay:(id&MKOverlay&) //alsoremoveOverlays:(NSArray*)
也有和cellForRowAtIndexPath或viewForAnnotation相同的机制:
- (MKOverlayView *)mapView:(MKMapView *)sender
viewForOverlay:(id &MKOverlay&)
MKOverlayView基本上就是实现了类似drawRect的东西,它不叫drawRect,而是:
- (void)drawMapRect:(MKMapRect)mapRect
zoomScale:(MKZoomScale)zoomScale
inContext:(CGContextRef)
不调用UIGraphics获得context,它给你一个context来做CoreGraphics的绘制。
要用上次的shutterbug,把它加入Spli View,details一侧是master里对应项的地图。
从对象库中拖出一个Spli View,并删除它的master,用control+drag的方式指定新的master。重新创建一个UIViewController的子类叫MapViewController,设置detail的类为MapViewController,再对象库中拖一个Map View到detail中,然后为mapView创建一个outlet到MapViewController,这时会出现一个红色的error,这是因为MKMapView所属的framework还没有链接到这个app。那么要怎么解决呢?回到project navigator,点击project,再点击target,然后去到build phases,可以看到link binary with libraries,这就是添加framework的地方,选择MapKit.framework和CoreLocation.framework。回到MapViewController,#import &MapKit/MapKit.h&,红色的error就会消失。
在MapViewController.h文件中创建一个model,是annotations数组,最终是要把这些东西传递给Map View。但因为Map View不是public的,所以需要有一些公共的API。
对FlickrPhotoTableViewController.m文件添加了以下一些代码:
- (NSArray *)mapAnnotations
NSMutableArray *annotations = [NSMutableArray arrayWithCapacity:[self.photos count]];
for (NSDictionary *photo in self.photos) {
[annotations addObject:[FlickrPhotoAnnotation annotationForPhoto:photo]];
- (void)updateSplitViewDetail
id detail = [self.splitViewController.viewControllers lastObject];
if ([detail isKindOfClass:[MapViewController class]]) {
MapViewController *mapVC = (MapViewController *)
mapVC.delegate =
mapVC.annotations = [self mapAnnotations];
- (void)setPhotos:(NSArray *)photos
if (_photos != photos) {
[self updateSplitViewDetail];
// Model changed, so update our View (the table)
if (self.tableView.window) [self.tableView reloadData];
创建一个实现了MKAnnotation protocol的NSOject的子类,将其命名为FlickrPhotoAnnotation,FlickrPhotoAnnotation.h文件代码如下:
#import &Foundation/Foundation.h&
#import &MapKit/MapKit.h&
@interface FlickrPhotoAnnotation : NSObject &MKAnnotation&
+ (FlickrPhotoAnnotation *)annotationForPhoto:(NSDictionary *) // Flickr photo dictionary
@property (nonatomic, strong) NSDictionary *
FlickrPhotoAnnotation.m文件代码:
#import "FlickrPhotoAnnotation.h"
#import "FlickrFetcher.h"
@implementation FlickrPhotoAnnotation
@synthesize photo = _
+ (FlickrPhotoAnnotation *)annotationForPhoto:(NSDictionary *)photo
FlickrPhotoAnnotation *annotation = [[FlickrPhotoAnnotation alloc] init];
annotation.photo =
#pragma mark - MKAnnotation
- (NSString *)title
return [self.photo objectForKey:FLICKR_PHOTO_TITLE];
- (NSString *)subtitle
return [self.photo valueForKeyPath:FLICKR_PHOTO_DESCRIPTION];
- (CLLocationCoordinate2D)coordinate
CLLocationCoordinate2D
coordinate.latitude = [[self.photo objectForKey:FLICKR_LATITUDE] doubleValue];
coordinate.longitude = [[self.photo objectForKey:FLICKR_LONGITUDE] doubleValue];
当你有一个通用类,想让它从另一个类获取数据的时候,你要怎么做?子类或delegation。
MapViewController.h文件代码:
#import &UIKit/UIKit.h&
#import &MapKit/MapKit.h&
@class MapViewC
@protocol MapViewControllerDelegate &NSObject&
- (UIImage *)mapViewController:(MapViewController *)sender imageForAnnotation:(id &MKAnnotation&)
@interface MapViewController : UIViewController
@property (nonatomic, strong) NSArray * // of id &MKAnnotation&
@property (nonatomic, weak) id &MapViewControllerDelegate& delegate;
MapViewController.m文件代码:
#import "MapViewController.h"
@interface MapViewController() &MKMapViewDelegate&
@property (weak, nonatomic) IBOutlet MKMapView *mapV
@implementation MapViewController
@synthesize mapView = _mapV
@synthesize annotations = _
@synthesize delegate = _
#pragma mark - Synchronize Model and View
- (void)updateMapView
if (self.mapView.annotations) [self.mapView removeAnnotations:self.mapView.annotations];
if (self.annotations) [self.mapView addAnnotations:self.annotations];
- (void)setMapView:(MKMapView *)mapView
_mapView = mapV
[self updateMapView];
- (void)setAnnotations:(NSArray *)annotations
_annotations =
[self updateMapView];
#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id&MKAnnotation&)annotation
MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
if (!aView) {
aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
aView.canShowCallout = YES;
aView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
// could put a rightCalloutAccessoryView here
aView.annotation =
[(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView
UIImage *image = [self.delegate mapViewController:self imageForAnnotation:aView.annotation];
[(UIImageView *)aView.leftCalloutAccessoryView setImage:image];
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
NSLog(@"callout accessory tapped for annotation %@", [view.annotation title]);
#pragma mark - View Controller Lifecycle
- (void)viewDidLoad
[super viewDidLoad];
self.mapView.delegate =
- (void)viewDidUnload
[self setMapView:nil];
[super viewDidUnload];
#pragma mark - Autorotation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
return YES;
阅读(...) 评论()}

我要回帖

更多关于 地图插件 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信