1
我已經開始閱讀關於Google地圖的信息,並且自過去3天以來我已經能夠實施一些事情。除此之外,我還必須閱讀有關Web服務的基礎知識,所以我已閱讀了關於使用AFNetworking庫的信息。現在,我已經能夠實現的事情是:IOS中谷歌地圖上的指示
- 實現谷歌地圖
- 瞭解地圖
- 在地圖上繪製路徑訪問Web服務
- 描繪軌跡的兩個點之間,包括航點
這是此實施的代碼:
//Showing Map
{
GMSCameraPosition *cameraPosition = [GMSCameraPosition
cameraWithLatitude:-33.86 longitude:151.20 zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:cameraPosition];
mapView_.myLocationEnabled = YES;
mapView_.mapType = kGMSTypeNormal;
mapView_.settings.myLocationButton = YES;
mapView_.delegate = self;
self.view = mapView_;
//Showing marker
GMSMarker *marker = [GMSMarker new];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;
[self GETRequest];//method to implement google maps api
}
這裏是我的方法的實現「的GetRequest」:
-(void)GETRequest{
NSURL *url = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/directions/json?origin=-33.86,151.20&destination=-32.90,151.80&waypoints=-33.30,151.50"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:urlRequest];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation,id responseObject){
NSLog(@"success");
NSLog(@"%@",responseObject);
GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(-33.86, 151.20)];
[path addCoordinate:CLLocationCoordinate2DMake(-25.30, 140.50)];
[path addCoordinate:CLLocationCoordinate2DMake(-32.90, 151.80)];
GMSPolyline *line = [GMSPolyline polylineWithPath:path];
line.strokeWidth = 2;
line.map = mapView_;
self.view = mapView_;
} failure
:^(AFHTTPRequestOperation *operation,id responseObject){
NSLog(@"failure");
}];
[operation start];
這裏是我的輸出截圖:
現在我的問題是:路由總是得出這樣的直行呢?我想查看具體的方向,但Google API for directions文檔不提供任何代碼或解釋。
雅我在印刷那些東西以及....非常感謝給我一個谷歌地圖方向的方向;-)我會盡力實現它,我會明天回來.....謝謝很多........ – Reckoner
:最後完成....... NSString * polyLinePath = responseObject [@「routes」] [0] [@「overview_polyline」] [@「points」]; .. ........非常感謝!!! – Reckoner
傑夫你能幫我解決這個問題嗎...... http://stackoverflow.com/questions/33013481/update-marker-position-in-google-maps-in-ios-app ...... 我需要那個! – Reckoner