我想创建视图控制器来设置参数,然后通过长舔将GPS标记添加到谷歌地图上。我从故事板创建UI,名称为Main_iPhone.storyboard
以下是我的代码:
-(void) mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate{
SliderViewController * object = [[SliderViewController alloc] init];
[self presentViewController:object animated:YES completion:nil];
//SliderViewController *secondView = [[SliderViewController alloc] initWithNibName:@"SliderViewController" bundle:[NSBundle mainBundle]];
//[self.navigationController pushViewController:secondView animated:YES];
CheckPoints *myCar=[[CheckPoints alloc] init];
[myCar setState:0];
[myCar setLatitude:coordinate.latitude];
[myCar setLongitude:coordinate.longitude];
NSString* theTextValue = @"Desitnation";
[myCar setDesp:theTextValue];
[array addObject:myCar];
CheckPoints *lastChk = array.lastObject;
[self writeToTextFile:[NSString stringWithFormat:@"%@%@%@%@%@%@", lastChk.getDesp , @"\n",[NSString stringWithFormat:@"%f", lastChk.getLatitude],
@"\n", [NSString stringWithFormat:@"%f", lastChk.getLongitude], @"\n" ]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setFloat:lastChk.getLatitude forKey:@"lati"];
[defaults setFloat:lastChk.getLongitude forKey:@"longi"];
[defaults setObject:lastChk.getDesp forKey:@"desp"];
[defaults synchronize];
for (int i = 0; i < [array count]; i++) {
CheckPoints *current = [array objectAtIndex:i];
if(current.getLatitude != lastChk.getLatitude && current.getLongitude != lastChk.getLongitude){
[current setState:1];
NSString* previousTitle = [NSString stringWithFormat:@"%@%@", @"Checkpoint" ,[NSString stringWithFormat:@"%i", i+1]];
[current setDesp:previousTitle];
}
}
[self addMarkers];
}
答案 0 :(得分:0)
您可以在地图上添加长触摸手势,然后在手势上调用您的代码。在调用视图后,您可以加载。