在我的应用程序中,我有一组位置及其相关注释。我有一个单击它的按钮,我转到一个调用 URL Web 服务的方法来获取谷歌街景。
我的代码是:
- (NSString*)urlStreetview:(id<MKAnnotation>)annotation{
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];
NSLog(@"lat:%f",pinLocation.coordinate.latitude);
NSLog(@"lon:%f",pinLocation.coordinate.longitude);
NSString *lat_string = [[NSString alloc] initWithFormat:@"%f", pinLocation.coordinate.latitude];
NSString *lon_string = [[NSString alloc] initWithFormat:@"%f", pinLocation.coordinate.longitude];
NSString *url1 = [NSString stringWithFormat:@"http:myweb/streetview.php"];
NSString *url2 = [url1 stringByAppendingString: @"?lat="];
NSString *url3 = [url2 stringByAppendingString:lat_string];
NSString *url4 = [url3 stringByAppendingString:@"&lon="];
NSString *url = [url4 stringByAppendingString:lon_string];
NSLog(@"url:%@",url);
return url;
}
我编写了前面的方法来获得一个由注释的 LatLong 组成的 url。
我在注释针上有一个名为 PressMe 的按钮。当我推送它时,我想执行以前的方法,调用 url,但我不明白如何将选定的注释传递给 streetView 方法。
- (IBAction)PressMe:(id)sender
{
UIViewController *webViewController = [[[UIViewController alloc] init] autorelease];
UIWebView *uiWebView = [[[UIWebView alloc] initWithFrame: CGRectMake(0,0,320,480)] autorelease];
[uiWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [self urlStreetview: ????]]]]; //HERE IS MY MY PROBLEM
[webViewController.view addSubview: uiWebView];
webViewController.title = @"web bar";
[self.navigationController pushViewController:webViewController animated:YES];
//[[self navigationController] pushViewController:thirdViewController animated:YES];
}
提前致谢!