iphone程式內調用Google地圖

來源:互聯網
上載者:User

使用CLLocationManager類,MKMapView。並且實現<MKMapViewDelegate,CLLocationManagerDelegate>
//初始化CLLocationManager,CLLocationManager獲得當前地理座標
locmanager=[[CLLocationManager alloc]init];

[locmanager setDelegate:self];
 //設定精確度
[locmanagersetDesiredAccuracy:kCLLocationAccuracyBest];

[locmanagerstartUpdatingLocation];
執行完以後,會自動調用代理方法:

在代理方法:

- (void)locationManager:(CLLocationManager *)managerdidUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation{
//初始化矩形大小
 CGRect rect=CGRectMake(0,0,320,460);
//設定地圖大小為矩形大小
map=[[MKMapView alloc] initWithFrame:rect];

CLLocationCoordinate2Dloc=[newLocation coordinate];
lat=loc.latitude;
lon=loc.longitude;

//coordinate座標
CLLocationCoordinate2DtheCoordinate;
CLLocationCoordinate2DtheCenter;

//theCoordinate.latitude=lat;
//theCoordinate.longitude=lon;
theCoordinate=loc;
[map setDelegate:self];
//設定地圖顯示的類型,有衛星地圖,道路,等
[map setMapType:MKMapTypeStandard];
//[mapsetMapType:MKMapTypeSatellite];
//地區座標Region(地區,地區)

MKCoordinateRegiontheRegin;
//theCenter.latitude=lat;
//theCenter.longitude=lon;
theCenter=loc;
theRegin.center=theCenter;

//座標間距(span:間隔,間距)
MKCoordinateSpantheSpan;

theSpan.latitudeDelta=0.1;
theSpan.longitudeDelta=0.1;
//設定地圖顯示的地區,
theRegin.span=theSpan;
//[mapsetRegion:theRegin];
[mapregionThatFits:theRegin];
map.showsUserLocation=YES;
[self.viewaddSubview:map];

}

- (MKAnnotationView *)mapView:(MKMapView *)mapViewviewForAnnotation:(id<MKAnnotation>)annotation{
NSLog(@"-------viewForAnnotation-------");
//此類可以顯示針一樣的表徵圖
MKPinAnnotationView*newAnnotation=[[MKPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:@"annotation1"];

//newAnnotation.animatesDrop=YES;
//newAnnotation.animatesDrop=NO;

newAnnotation.pinColor=MKPinAnnotationColorPurple;
//顯示標誌提示
newAnnotation.canShowCallout=YES;
return newAnnotation;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.