2016-05-18 10 views
0

私は道順を示すための地図を持っています。私は命令でアノテーションを表示する方向をタップすることができますが、私がしようとしているのは、方向座標にマーカーを追加することです。ここで私は現在、使用していたコードされていますIOSのObjective-CアプリでGoogleマップにマーカー画像を追加

-(void) getDirectionsFromStart: (CLLocation*) start toEnd: (CLLocation*) end 
{ 

NSString *mapDir = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=false", start.coordinate.latitude, start.coordinate.longitude, end.coordinate.latitude, end.coordinate.longitude]; 
if ([self.directionsArray count] == 0) { 

//parse the string response and then draw the points on a map 
    NSError *error; 
    NSString *response = [NSString stringWithContentsOfURL:[NSURL URLWithString:mapDir] encoding:NSUTF8StringEncoding error:&error]; 
    if (response == nil) { 
     NSLog(@"Google Maps error: %@", [error localizedDescription]); 
     NSLog(@"Google Maps recovery: %@", [error localizedRecoverySuggestion]); 
     //[self getDirectionsFromStart:nil toEnd:nil]; 
    } 
    self.directionsArray = [gMapsJsonDirectionsParser parseJsonToMapDirections:response]; 
} 
for (gMapsJourneyLeg *leg in self.directionsArray) { 
    @autoreleasepool { 

    self.directionsHeader.text = [NSString stringWithFormat:@"To %@ Taking: %@", leg.end_address, leg.duration.text]; 
    for (gMapsStep *step in leg.steps) { 
     MKPolyline *polyLine = [gMapsJsonDirectionsParser polylineWithEncodedString:step.polyLine]; 
     MKPolylineView *line = [[MKPolylineView alloc] initWithPolyline: polyLine]; 

     line.fillColor = [UIColor blueColor]; 
     line.strokeColor = [UIColor blueColor]; 
     line.lineWidth = 5; 
     [self.mapView addOverlay:polyLine]; 
     //[self.mapView setVisibleMapRect:polyLine.boundingMapRect]; 
     //map point code 
     MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; 
     point.coordinate = step.end_location.coordinate; 
     point.title = step.htmlInstructions; 

     [[self.mapView viewForAnnotation:point] setTag:1]; 
     UIImage *image = [UIImage imageNamed:@"marker_red.png"]; 
     [[self.mapView viewForAnnotation:point] setImage:image]; 

     [self.mapView addAnnotation:point]; 
    } 
    } 
} 

[self.tableView reloadData]; 
} 

を明確にするためには、注釈およびポリラインは、両方の罰金です、それはただのマーカーが表示されることはありませんです。 Google Docs for Markersのコードに

答えて

2

ベース:ここ

カスタム画像にマーカを追加するためのサンプルコードです。

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(51.5, -0.127); 
GMSMarker *london = [GMSMarker markerWithPosition:position]; 
london.title = @"London"; 
london.icon = [UIImage imageNamed:@"house"]; 
london.map = mapView_; 

はあなたのマーカーが表示されていない理由であるGMSMarker *london = [GMSMarker markerWithPosition:position];を設定していないかもしれませ。 markerPositionプロパティを追加しない場合は、カスタム画像を表示せずにマーカーを確認してください。

関連する問題