Как обновить адрес plist для Mapview? - PullRequest
0 голосов
/ 14 июня 2011

Я следую приведенному ниже коду, вывод можно распечатать на консоль, но как обновить на 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

1 Ответ

0 голосов
/ 14 июня 2011

Вы, должно быть, получаете лат-длинную информацию о местоположении.Вам нужно будет создать класс, который принимает протокол MKAnnotation, и добавить его экземпляр, хранящий местоположение, которое вы получите, к объекту MKMapView, используя метод addAnnotation:.Если местоположение находится в отображаемой области карты, объект представления карты вызовет метод делегата mapView:viewForAnnotation:, чтобы получить представление, отображаемое для этой аннотации.Таким образом, вам придется стать делегатом, приняв протокол MKMapViewDelegate.Реализуйте метод mapView:viewForAnnotation:, чтобы вернуть экземпляр MKPinAnnotationView или ваш собственный подкласс 'MKAnnotationView.

Если местоположение не находится в отображаемой области, используйте метод setRegion:animated: для перемещения в местоположение.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...