Я импортирую Google Map SDK в наше приложение, и оно работает нормально, но с одной проблемой.Это низкая детализация на карте, как на фото: фото Я представляю, что это из-за небольшого количества очков.Код, который я использую:
- (void)createPolyline {
KSVMapTasks* mapTasks = [[KSVMapTasks alloc] init];
CLLocation* locationObject = [[CLLocation alloc] initWithLatitude:self.marker.position.latitude longitude:self.marker.position.longitude];
[mapTasks fetchPolylineWithOrigin:self.locationManager.location
destination:locationObject typeModel:KSVDriving
completionHandler:^(NSArray *routesArray) {
dispatch_async(dispatch_get_main_queue(), ^{
[self createOnMapPolyline:routesArray type:KSVDriving];
});
}];
[mapTasks fetchPolylineWithOrigin:self.locationManager.location
destination:locationObject typeModel:KSVWalking
completionHandler:^(NSArray *routesArray) {
dispatch_async(dispatch_get_main_queue(), ^{
[self createOnMapPolyline:routesArray type:KSVWalking];
});
}];
}
- (void)fetchPolylineWithOrigin:(CLLocation *)origin
destination:(CLLocation *)destination
typeModel:(KSVTypeModel)typeModelParametr
completionHandler:(void (^_Nonnull)(NSArray *routesArray)) completionHandler
{
NSString* type = nil;
switch (typeModelParametr) {
case KSVDriving:
type = @"driving";
break;
case KSVWalking:
type = @"walking";
break;
}
NSString* lang = [Preferences lang];
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=%@&language=%@&mode=%@&key=%@", directionsAPI, originString, destinationString,lang, type, @"AIzaSyDdTGy9qFpyKLK2UebNR-Hm_bzGgFlAxtI"];
NSURL *directionsUrl = [NSURL URLWithString:directionsUrlString];
NSURLSessionDataTask *fetchDirectionsTask = [[NSURLSession sharedSession]
dataTaskWithURL:directionsUrl
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
if(!data && !response)
{
if(completionHandler)
completionHandler(nil);
} else if (response) {
NSLog(@"%@", response);
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSArray *routesArray = [json objectForKey:@"routes"];
completionHandler(routesArray);
} else if (error) {
if(completionHandler)
completionHandler(nil);
}
}];
[fetchDirectionsTask resume];
}
Это ответ для пути и других свойств.И
Для рисования:
- (void) createOnMapPolyline:(NSArray*) routesArray type:(KSVTypeModel) type {
GMSPolyline *polyline = nil;
if ([routesArray count] > 0)
{
NSDictionary *routeDict = [routesArray objectAtIndex:0];
NSArray* legs = [routeDict objectForKey:@"legs"];
NSDictionary* durationDict = [legs[0] objectForKey:@"duration"];
NSDictionary* distanceDict = [legs[0] objectForKey:@"distance"];
NSString* duration = [durationDict objectForKey:@"text"];
NSString* distance = [distanceDict objectForKey:@"text"];
NSDictionary *routeOverviewPolyline = [routeDict objectForKey:@"overview_polyline"];
NSString *points = [routeOverviewPolyline objectForKey:@"points"];
GMSPath *path = [GMSPath pathFromEncodedPath:points];
polyline = [GMSPolyline polylineWithPath:path];
....
В приложении для Android с похожим кодом его работа отлично.СПАСИБО ЗА ВАШУ ПОМОЩЬ!