iOS-在没有动画的情况下清除Google地图数据
我正在实施谷歌地图,我需要在每隔几秒(30-50秒)后清除地图数据(所有多段线+标记)。正如我们所知,我们可以使用iOS-在没有动画的情况下清除Google地图数据,ios,objective-c,google-maps,gmsmapview,Ios,Objective C,Google Maps,Gmsmapview,我正在实施谷歌地图,我需要在每隔几秒(30-50秒)后清除地图数据(所有多段线+标记)。正如我们所知,我们可以使用[yourMap clear]但当我这样做的时候,谷歌地图会制作一些动画(就在调用clear方法之后),然后它会在地图上显示新的数据,我不想要这个小动画。注意:我每隔20-50秒调用此方法drawPolylineOnMap\u ShowDriverRecurrentLoc,以在地图上显示最新数据 -(void)drawPolylineOnMap_ShowDriverCurrentLo
[yourMap clear]代码>但当我这样做的时候,谷歌地图会制作一些动画(就在调用clear方法之后),然后它会在地图上显示新的数据,我不想要这个小动画。注意:我每隔20-50秒调用此方法drawPolylineOnMap\u ShowDriverRecurrentLoc,以在地图上显示最新数据
-(void)drawPolylineOnMap_ShowDriverCurrentLoc :(NSDictionary*)dicResponse
{
// clear current map
[mapViewGMS clear];
NSString *driver_coordinates= [dicResponse valueForKey:@"one"];
NSArray *itemsDriver = [driver_coordinates componentsSeparatedByString:@","]; //take the one array for split the string
NSString *sourceLongi=[itemsDriver objectAtIndex:0]; //shows Description
NSString *sourceLati=[itemsDriver objectAtIndex:1]; //
NSString *clientLoc= [dicResponse valueForKey:@"two"];
NSArray *itemsClient = [clientLoc componentsSeparatedByString:@","]; //take the one array for split the string
NSString *destLongi=[itemsClient objectAtIndex:0]; //shows Description
NSString *destLati=[itemsClient objectAtIndex:1]; //Shows Data
CLLocation *myOrigin=[[CLLocation alloc]initWithLatitude:[sourceLati floatValue] longitude:[sourceLongi floatValue]];
CLLocation *myDestination=[[CLLocation alloc]initWithLatitude:[destLati floatValue] longitude:[destLongi floatValue]];
[self fetchPolylineWithOriginForDriverCurrLoc:myOrigin destination:myDestination completionHandler:^(GMSPolyline *polyline)
{
dispatch_async(dispatch_get_main_queue(), ^{
if(polyline) {
polyline.map = mapViewGMS;
}
});
}];
}
-(void)fetchPolylineWithOriginForDriverCurrLoc:(CLLocation *)origin destination:(CLLocation *)destination completionHandler:(void (^)(GMSPolyline *))completionHandler
{
NSString *destLati= [NSString stringWithFormat:@"%f", destination.coordinate.latitude];
NSString *destLongi= [NSString stringWithFormat:@"%f", destination.coordinate.longitude];
NSString *originString = [NSString stringWithFormat:@"%f,%f", origin.coordinate.latitude, origin.coordinate.longitude];
NSString *destinationString = [NSString stringWithFormat:@"%f,%f", destination.coordinate.latitude, destination.coordinate.longitude];
NSString *directionsAPI = @"https://maps.googleapis.com/maps/api/directions/json?";
NSString *directionsUrlString = [NSString stringWithFormat:@"%@&origin=%@&destination=%@&mode=driving", directionsAPI, originString, destinationString];
NSURL *directionsUrl = [NSURL URLWithString:directionsUrlString];
NSURLSessionDataTask *fetchDirectionsTask = [[NSURLSession sharedSession] dataTaskWithURL:directionsUrl completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if(error)
{
if(completionHandler)
completionHandler(nil);
return;
}
NSArray *routesArray = [json objectForKey:@"routes"];
__block GMSPolyline *polyline = nil;
if ([routesArray count] > 0)
{
NSDictionary *routeDict = [routesArray objectAtIndex:0];
NSDictionary *routeOverviewPolyline = [routeDict objectForKey:@"overview_polyline"];
NSString *points = [routeOverviewPolyline objectForKey:@"points"];
dispatch_async(dispatch_get_main_queue(), ^{
GMSPath *path = [GMSPath pathFromEncodedPath:points];
polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeColor = [UIColor redColor];//[UIColor colorWithRed:156/255.0f green:52/255.0f blue:104/255.0f alpha:1.0];
polyline.strokeWidth = 3.1f;
polyline.map = mapViewGMS ;
// add marker on source location
CLLocationCoordinate2D source = CLLocationCoordinate2DMake(origin.coordinate.latitude,origin.coordinate.longitude );
GMSMarker *markerSource = [GMSMarker markerWithPosition:source];
// markerSource.title = [NSString stringWithFormat:@"Estimated Start Trip at %@",globalTripStartTime];
markerSource.icon=[UIImage imageNamed:@"markerGreenCircle"];
markerSource.appearAnimation=0.2f;
markerSource.map = mapViewGMS;
// add marker on destination location
CLLocationCoordinate2D destiCordin = CLLocationCoordinate2DMake([destLati floatValue],[destLongi floatValue] );
GMSMarker *markerDestination = [GMSMarker markerWithPosition:destiCordin];
//markerDestination.title = [NSString stringWithFormat:@"Estimated End Trip at %@",globalTripEndTime];
markerDestination.icon=[UIImage imageNamed:@"markerRedCircle"];
markerDestination.appearAnimation=0.2f;
markerDestination.map = mapViewGMS;
// Focus map on pick up location, first find center b/w 2 locations
CLLocationCoordinate2D midpointBetweenCoordinate= [self midpointBetweenCoordinate:origin andCoordinate:destination];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:midpointBetweenCoordinate.latitude
longitude:midpointBetweenCoordinate.longitude
zoom:10.5];
mapViewGMS.camera=camera;
});
}
if(completionHandler)
completionHandler(polyline);
}];
[fetchDirectionsTask resume];
}