Iphone 注释Mapkit的传递坐标
在我的应用程序中,我有一组位置和它们的相对注释。我有一个按钮,点击它,我去一个方法,调用一个URL网络服务,以获得谷歌街景 我的代码是:Iphone 注释Mapkit的传递坐标,iphone,mapkit,Iphone,Mapkit,在我的应用程序中,我有一组位置和它们的相对注释。我有一个按钮,点击它,我去一个方法,调用一个URL网络服务,以获得谷歌街景 我的代码是: - (NSString*)urlStreetview:(id<MKAnnotation>)annotation{ CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotatio
- (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;
}
提前谢谢 我将自己回答我的问题。我只是解决了我的问题,它工作得很好。该代码允许显示web视图,以便拥有注释地图工具包注释的steet view google服务。显然,由于我是一名相对较新的iphone开发人员,如果有人想添加/建议/改进,欢迎他 我的按钮实现:
- (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]]];
[webViewController.view addSubview: uiWebView];
webViewController.title = @"web bar";
[self.navigationController pushViewController:webViewController animated:YES];
//[[self navigationController] pushViewController:thirdViewController animated:YES];
}
通过这个按钮,我调用我的(以下)方法“urlStreetview”,在选择注释的情况下,组成一个字符串,以便使用apropriete GET php参数生成一个完整的url。url是我的(非常简单的)web服务的方向,它允许调用GoogleAPI街景
- (NSString*)urlStreetview{
//there can only be one selected annotation so get the one at index 0
id<MKAnnotation> selectedAnnotation = [_mapView.selectedAnnotations objectAtIndex:0];
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:selectedAnnotation.coordinate.latitude longitude:selectedAnnotation.coordinate.longitude];
我希望它能有用 按钮是如何添加的,以及它与注释视图的关系如何?这是获得感兴趣的批注信息的关键。我的按钮是通过方法添加的:-(MKAnnotationView*)mapView:(MKMapView*)mapView视图用于批注:(id)批注{//left button details UIButton*left_button=[[UIButton alloc]initWithFrame:cRectMake(0,0,20,20)];[left_button setImage:[UIImage ImageName:@“add.png”]用于状态:UIControlStateNormal];[left_按钮添加目标:自我操作:@选择器(按:)用于控制事件:UIControlEventTouchUpInside];annotationView.LeftCallAccessoryView=左按钮//
- (NSString*)urlStreetview{
//there can only be one selected annotation so get the one at index 0
id<MKAnnotation> selectedAnnotation = [_mapView.selectedAnnotations objectAtIndex:0];
CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:selectedAnnotation.coordinate.latitude longitude:selectedAnnotation.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://myurl/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;
}