`
119568242
  • 浏览: 431014 次
  • 性别: Icon_minigender_1
  • 来自: 深圳/湛江
社区版块
存档分类
最新评论

[ios6] 基于CoreLocation 的地图demo

    博客分类:
  • ios
 
阅读更多

自定义showCallout 左右view

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    MKAnnotationView *aView=[mapView dequeueReusableAnnotationViewWithIdentifier:@"testMapView"];
    if(!aView){
        aView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"testMapView"];
//这里是用的MKPinAnnotationView 初始化 当然也可以用MKAnnotationView 只是用MKAnnotationView就必须对MKAnnotationView对象.image赋值 否则 没有图钉显示标记位置
        aView.canShowCallout=YES;
        //设置是否显示ShowCallout
        
        }
    aView.annotation=annotation;
    UIImageView *imageV=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//0,0,30,30是组不错的数据。
    imageV.image=[UIImage imageNamed:@"Default.png"];
    aView.leftCalloutAccessoryView=imageV;


//    aView.image=[UIImage imageNamed:@"Default.png"];

//    aView.image用于修改在地图上标记的图钉


    return aView;

}


实现MKMapViewDelegate协议
并设置当前mapView.delegate
 

 

关于annotation 

 

MyAnnotation 用于作为放入MapView annotation数组的对象[放入此数组的id需旅行 <MKAnnotation>协议]
此协议是 readOnly的几个属性的"get"方法实现。因为readOnly 所以无法对其赋值。故传入一个“辞典” 然后在对应的“get”方法中去 词典中去相应的数据。

MyAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyAnnotation : NSObject<MKAnnotation>


+(MyAnnotation*)initWithNSMutableDictionary:(NSMutableDictionary *)ns;

@end


MyAnnotation.m


#import "MyAnnotation.h"

@interface MyAnnotation()
@property NSMutableDictionary *save;

@end

@implementation MyAnnotation

@synthesize save=_save;

+ (MyAnnotation *)initWithNSMutableDictionary:(NSMutableDictionary *)ns{
    MyAnnotation *ma=[[MyAnnotation alloc]init];
    ma.save=ns;
    return ma;
}

#pragma mark - <Annotation>

-(NSString *)title{
    return [self.save objectForKey:@"title"];
}

-(NSString *)subtitle{
    return [self.save objectForKey:@"subTitle"];

}

-(CLLocationCoordinate2D)coordinate{
    CLLocationCoordinate2D result;
    result.latitude=20.0;//纬度
    result.longitude=30.0;//经度
    return result;
}

@end

 

 

 VC相关

 

 

当mapView或annotations 被设置时则执行更新。刷新界面
保证数据同步展示在屏幕。

#import "ViewController.h"
#import <MapKit/MapKit.h>
#import "MyAnnotation.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet MKMapView *myMapView;
@property (strong,nonatomic) NSArray *annotations;
@end

@implementation ViewController

@synthesize myMapView=_myMapView;
@synthesize annotations=_annotations;

-(void)setAnnotations:(NSArray *)annotations{
    if(_annotations!=annotations){
        _annotations=annotations;
        [self update];
    }
}

-(void)setMyMapView:(MKMapView *)myMapView{
    if(_myMapView!=myMapView){
        _myMapView=myMapView;
        [self update];
    }
}

- (void)update{
    if(self.myMapView.annotations){
        [self.myMapView removeAnnotations:self.myMapView.annotations];
    }
    if(self.annotations){
        [self.myMapView addAnnotations:self.annotations];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSMutableDictionary *nsTemp=[[NSMutableDictionary alloc]init];
    [nsTemp setObject:@"poolo's title" forKey:@"title"];
    [nsTemp setObject:@"poolo's SubTitle" forKey:@"subTitle"];
    self.annotations=@[[MyAnnotation initWithNSMutableDictionary:nsTemp]];
	 
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
分享到:
评论

相关推荐

    449苹果手机ios基于GPS定位Demo源程序毕业课程源码设计

    本篇将详细介绍一份iOS基于GPS定位的Demo源程序,这份源码设计是专门为计算机科学和软件工程领域的学生设计的毕业课程项目。项目中使用了Xcode作为开发环境,iOS作为目标运行平台,主要目的是为了让开发者学习并掌握...

    IOS map 定位 Demo

    在iOS开发中,地图定位是应用开发中的常见需求,尤其是对于提供导航、位置服务或基于位置的社交应用来说。这个“iOS Map 定位 Demo”提供了实现这一功能的实例代码,帮助开发者理解如何在自己的应用中集成苹果的地图...

    ios-地图定位签到及离线签到功能实现.zip

    本文将深入探讨如何实现iOS上的地图定位签到及离线签到功能,基于提供的资源"ios-地图定位签到及离线签到功能实现.zip"。 首先,我们要了解iOS地图定位的基础知识。iOS提供了Core Location框架,它允许开发者获取...

    iOS 经纬度坐标指南针效果

    在iOS开发中,实现一个基于经纬度坐标的指南针效果是一项常见的需求,特别是在地图应用或者户外导航类应用中。这个“iOS 经纬度坐标指南针效果”项目提供了一个简单的指南针Demo,它能够根据用户的实时地理位置信息...

    IOS地图定位

    本DEMO展示了如何在iOS应用中集成地图和定位服务,提供了周边搜索和关键字搜索的功能,使得用户能够轻松找到附近的兴趣点或者通过输入特定关键词进行搜索。以下是关于iOS地图定位的关键知识点和实现细节: 1. **...

    分享一个GPS测速Demo

    1. 定位API:在Android和iOS等移动平台上,开发者可以使用系统提供的定位API,如Android的LocationManager和iOS的CoreLocation框架,来请求和解析GPS数据。 2. 获取速度信息:从GPS坐标中提取速度信息,通常GPS坐标...

    iso_location_定位

    在iOS开发中,获取设备的当前位置是常见的需求,特别是在实现地图应用、导航服务或提供基于位置的个性化功能时。在iOS8及更高版本中,Apple提供了Core Location框架,用于处理定位服务。本教程将深入讲解如何利用iOS...

    MapKitDemo

    MapKitDemo是一个基于Swift开发的示例项目,它利用了Apple的MapKit框架来展示如何在iOS应用中集成地图功能。MapKit框架是Apple提供的一种强大的工具,它允许开发者将地图、定位服务以及路线导航等功能无缝地融入到...

    yandex-maps-test-demo:演示项目,用于使用YandexMapsMobile测试用户位置和方向显示

    总的来说,"yandex-maps-test-demo"项目是一个实用的学习资源,它涵盖了Swift编程、iOS开发、地图服务集成以及定位服务应用等多个重要知识点,对于想要深入了解这方面的开发者来说极具价值。通过深入研究和实践这个...

Global site tag (gtag.js) - Google Analytics