代码改变世界

ios开发中地图应用

2013-04-11 17:06  三戒1993  阅读(105)  评论(0编辑  收藏  举报
开发iphone应用程序中的地图,目前常用的就是百度地图和Google地图。
对于新手来说,找对资料永远是最重要的,当然,最好的资料都来自于官网(版本也是最新的)。还有就是官网带的示例代码。
1、百度地图
参考:http://dev.baidu.com/wiki/imap/index.php?title=iOS%E5%B9%B3%E5%8F%B0/%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97
多看几遍,再多看看示例代码。
以目标坐标作为标注的示例为:

BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];

            CLLocationCoordinate2D coord=CLLocationCoordinate2DMake(mStore.mnLatitude, mStore.mnLongitude);// 商家坐标

            mapView.centerCoordinate = coor; // 以商家坐标为中心

            annotation.coordinate = coor;

            annotation.title = mStore.mstrName;

            [mapView addAnnotation:annotation];

2、google地图

参考:https://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html

CLLocationCoordinate2D coord=CLLocationCoordinate2DMake(mStore.mnLatitude, mStore.mnLongitude);// 商家坐标

CLRegion *newRegion = [[CLRegion alloc] initCircularRegionWithCenter:coord

radius:1000.0

identifier:[NSString stringWithFormat:@"%f, %f", regionsMapView.centerCoordinate.latitude, regionsMapView.centerCoordinate.longitude]];

// Create an annotation to show where the region is located on the map.

RegionAnnotation *myRegionAnnotation = [[RegionAnnotation alloc] initWithCLRegion:newRegion];

myRegionAnnotation.coordinate = newRegion.center;

myRegionAnnotation.title = mStore.mstrName;

// 定位到目标坐标

MKCoordinateRegion storeLocation = MKCoordinateRegionMakeWithDistance(coord, 4500.0, 4500.0); // 值越小,地图越大,越精确

[regionsMapView setRegion:storeLocation animated:YES];

[regionsMapView addAnnotation:myRegionAnnotation];

[myRegionAnnotation release];

// Start monitoring the newly created region.

[locationManager startMonitoringForRegion:newRegion desiredAccuracy:kCLLocationAccuracyBest];

[newRegion release];