Нарисуйте маршруты с помощью Google Maps iOS.IOS

Программируем под IOS
Ответить
Anonymous
 Нарисуйте маршруты с помощью Google Maps iOS.

Сообщение Anonymous »

Я получаю GMSPolyline в произвольное местоположение, но не получаю направление маршрута (GMSPolyline) из местоположения пользователя в какое-то пользовательское местоположение.

Я разместил GMSMapView и сохранил основное местоположение. Я обновляю маршрут в методе делегата основного местоположения (locationManager: didUpdateLocations:).

Я хочу использовать Google Maps для iOS SDK, поскольку в Apple Maps нет направлений в нужной мне стране. Мой код ниже:

- (void)viewDidLoad
{
[super viewDidLoad];

waypointStrings_ = [[NSMutableArray alloc]init];

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.latitude longitude:self.longitude zoom:13];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;

CLLocationManager *locManager = [[CLLocationManager alloc] init];
if ( [CLLocationManager locationServicesEnabled] ) {
[locManager setDelegate:self];
[locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locManager startUpdatingLocation];
}
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocationCoordinate2D userCoordinate = [[locations lastObject] coordinate];

GMSMarker *marker = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake(self.latitude,self.longitude)];
marker.map = mapView_;
NSString *majlisPositionString = [[NSString alloc] initWithFormat:@"%f,%f", self.latitude,self.longitude];
[waypointStrings_ addObject:majlisPositionString];

GMSMarker *userMarker = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake(userCoordinate.latitude, userCoordinate.longitude)];
userMarker.map = mapView_;
NSString *userPositionString = [[NSString alloc] initWithFormat:@"%f,%f", userCoordinate.latitude, userCoordinate.longitude];
[waypointStrings_ addObject:userPositionString];

NSString *sensor = @"false";
NSArray *parameters = [NSArray arrayWithObjects:sensor, waypointStrings_, nil];
NSArray *keys = [NSArray arrayWithObjects:@"sensor", @"waypoints", nil];
NSDictionary *query = [NSDictionary dictionaryWithObjects:parameters forKeys:keys];
MDDirectionService *mds=[[MDDirectionService alloc] init];
SEL selector = @selector(addDirections:);
[mds setDirectionsQuery:query withSelector:selector withDelegate:self];
}

- (void)addDirections:(NSDictionary *)json {

NSDictionary *routes = [json objectForKey:@"routes"][0];

NSDictionary *route = [routes objectForKey:@"overview_polyline"];
NSString *overview_route = [route objectForKey:@"points"];
GMSPath *path = [GMSPath pathFromEncodedPath:overview_route];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.map = mapView_;
}


Подробнее здесь: https://stackoverflow.com/questions/243 ... e-maps-ios
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»