日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iphone:MKMapView

發(fā)布時間:2025/3/15 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iphone:MKMapView 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在iphone上實(shí)現(xiàn)地圖并不難。在Frameworks中加入MapKit.framework,要對mapView做相應(yīng)的操作時要添加一個outlet,記得#import<MapKit/MapKit.h>即可。

可參考博客?ios利用MKMapView實(shí)現(xiàn)簡單的地圖

?

顯示當(dāng)前自己位置:利用MKMapView顯示自己當(dāng)前位置的地圖


加入CoreLocation.framework,

VC遵循

<CLLocationManagerDelegate>

mapView.showsUserLocation=YES; CLLocationManager *locationManager = [[CLLocationManager alloc] init];//創(chuàng)建位置管理器 locationManager.delegate=self;//設(shè)置代理 locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度級別 locationManager.distanceFilter=1000.0f;//設(shè)置距離篩選器 [locationManager startUpdatingLocation];//啟動位置管理器 MKCoordinateSpan theSpan; //地圖的范圍 越小越精確 theSpan.latitudeDelta=0.05; theSpan.longitudeDelta=0.05; MKCoordinateRegion theRegion; theRegion.center=[[locationManager location] coordinate]; theRegion.span=theSpan; [mapView setRegion:theRegion]; [locationManager release];

?

在xcode中設(shè)置模擬器的位置,參照:

xcode4.2 模擬器定位 。xcode4.2 添加GPX文件。手工指定位置。?

?

給當(dāng)前位置加大頭針:

使用的是MKMapViewDelegate的mapView:viewForAnnotation:方法

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{MKPinAnnotationView *pinView = nil;static NSString *defaultPinID = @"com.invasivecode.pin";pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];pinView.pinColor = MKPinAnnotationColorRed;pinView.canShowCallout = YES;pinView.animatesDrop = YES;[mapView.userLocation setTitle:@"歐陸經(jīng)典"];[mapView.userLocation setSubtitle:@"vsp"];return pinView;}

參照:http://www.cocoachina.com/iphonedev/sdk/2010/1020/2216.html

?

MKAnnotationView 有一個image屬性,應(yīng)該可以改掉大頭針的圖形,改為flag?!

?

http://www.helmsmansoft.com/index.php/archives/980羅盤功能

?

?

//設(shè)置經(jīng)緯度

CLLocationCoordinate2D coord = {39.904667,116.408198};

//設(shè)置顯示范圍

MKCoordinateSpan span = MKCoordinateSpanMake(0.4,0.4);

//設(shè)置地圖顯示的中心和范圍

MKCoordinateRegion region = MKCoordinateRegionMake(coord,span);

//根據(jù)設(shè)置的信息進(jìn)行顯示

[mapView setRegion region animated:NO];

[mapView sizeToFit];

本文轉(zhuǎn)自老Zhan博客園博客,原文鏈接:http://www.cnblogs.com/mybkn/archive/2012/05/14/2499896.html,如需轉(zhuǎn)載請自行聯(lián)系原作者

總結(jié)

以上是生活随笔為你收集整理的iphone:MKMapView的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。