我按照下面的代码,输出可以打印到控制台,但是如何在MapView上更新?
- (void)viewDidLoad {
[super viewDidLoad];
/* We have our address */
NSString *oreillyAddress = @"1005 Gravenstein Highway North, Sebastopol, CA 95472, USA";
/* We will later insert the address and the format that we want our output in, into this API's URL */
NSString *geocodingURL = @"http://maps.google.com/maps/geo?q=%@&output=%@";
/* Insert the address and the output format into the URL */
NSString *finalURL = [NSString stringWithFormat:geocodingURL, oreillyAddress, GOOGLE_OUTPUT_FORMAT_CSV];
/* Now escape the URL using appropriate percentage marks */
finalURL = [finalURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
/* Create our URL */
NSURL *urlToCall = [NSURL URLWithString:finalURL];
/* And a request for the connection using the URL */
NSURLRequest *request = [NSURLRequest requestWithURL:urlToCall];
/* We will put all the connection's received data into this instance of the NSMutableData class */
NSMutableData *newMutableData = [[NSMutableData alloc] init];
self.connectionData = newMutableData;
[newMutableData release];
NSURLConnection *newConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
/* Create the connection and start the downloading of geocoding results */
self.myConnection = newConnection;
[newConnection release];
}
- (void) viewDidUnload{
[super viewDidUnload];
[self.myConnection cancel];
self.myConnection = nil;
self.connectionData = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
/* Support all orientations */
return YES;
}
- (void)dealloc {
[myConnection cancel];
[myConnection release];
[connectionData release];
[super dealloc];
}
@end
答案 0 :(得分:0)
您必须获取该位置的lat-long信息。您必须创建一个采用MKAnnotation
协议的类,并添加一个实例,使用MKMapView
方法存储您到addAnnotation:
对象的位置。如果位置位于地图的显示区域内,则地图视图对象将调用委托方法mapView:viewForAnnotation:
以获取要为该注释显示的视图。因此,您必须采用MKMapViewDelegate
协议成为委托人。实现mapView:viewForAnnotation:
方法以返回MKPinAnnotationView
实例或您自己的MKAnnotationView
的子类。
如果位置不在显示的区域内,请使用setRegion:animated:
方法移至该位置。