2016-04-21 56 views
1

我成功繪製了兩點之間的折線。但是我想把源點指向地圖的左側和目的點指向地圖的右側並在它們之間水平地畫線。GoogleMapSDK上的放置標記

任何想法真的很感激。

- (void)addMarkerOnMap { 

NSArray* arrMarkerData = @[ 
          @{@"icon":[UIImage imageNamed:@"blue"], @"position":[[CLLocation alloc]initWithLatitude:self.pickupAddCoordinate.latitude longitude:self.pickupAddCoordinate.longitude]}, 
          @{@"icon":[UIImage imageNamed:@"yellow"], @"position":[[CLLocation alloc]initWithLatitude:self.destinationAddCordinate.latitude longitude:self.destinationAddCordinate.longitude]} 
          ]; 

GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init]; 

//*> Including current location coordinate 
bounds = [bounds includingCoordinate:[LocationManager sharedManager].currentCoordinate]; 

for (NSDictionary *dict in arrMarkerData) 
{   
    //*> Add a marker in the center of the map. 

    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.icon  = (UIImage *)dict[@"icon"]; 
    marker.position = [(CLLocation *)dict[@"position"] coordinate]; 
    bounds   = [bounds includingCoordinate:marker.position]; 
    marker.map  = self.mapView; 

} 

//*> Fit Marker in bound  
if (self.isZoomMapView) 
{ 
    [self.mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:25.0f]]; 
    self.isZoomMapView = NO; 
} 

[self.mapView animateToBearing:-75]; 
[self getPathGoogleAPI_CallWithSource:self.pickupAddCoordinate andDestination:self.destinationAddCordinate];} 

此方法折線

- (void)getPathGoogleAPI_CallWithSource : (CLLocationCoordinate2D)sourceCoordinate andDestination: (CLLocationCoordinate2D)destinationCoordinate 
{ 

    NSString *getDriverLocationURl;  
    NSDictionary *postParams = @{k_API_GoogleOrigin  : [NSString stringWithFormat:@"%f,%f", sourceCoordinate.latitude, sourceCoordinate.longitude], 
           k_API_GoogleDestination : [NSString stringWithFormat:@"%f,%f",               destinationCoordinate.latitude, destinationCoordinate.longitude], 
           }; 

    getDriverLocationURl = [NSString stringWithFormat:@"%@", GOOGLE_DIRECTION_URL]; 

    [serviceManager apiCallUsingDataTaskHTTPMethod:GET url:getDriverLocationURl andParameters:postParams forTask:kTaskDrawRoute currentView:self.view accessToken:NO completionHandler:^(id response, NSError *error, TaskType task, BOOL success) 
    { 
     if (!error && response) 
     { 
      if ([[response valueForKey:RESPONSE_STATUS] isEqualToString:RESPONSE_OK]) 
      { 
       NSArray *routArr   = [response valueForKey:k_API_GoogleRoutes]; 

       GMSPath *path = [GMSPath pathFromEncodedPath:routArr[0][@"overview_polyline"][@"points"]]; 
       polyline = [GMSPolyline polylineWithPath:path]; 
       polyline.strokeColor = [UIColor blueColor]; 
       polyline.strokeWidth = 4.f; 
       polyline.map = self.mapView; 
      } 
      else 
      { 
       DLog(@"Google Direction : %@", [response valueForKey:RESPONSE_ERROR_MESSAGE]); 
      } 
     } 
     else 
     { 
      DLog(@"Google Direction : Sorry something went wrong"); 
     } 
    }]; 
} 
+0

您可以使用兩種圖像圖標標記(一個用於來源,另一個用於目的地)。 –

+0

我已經申請這個。我只是想從左到右顯示折線。 – Prabhat

+0

那麼你可以簡要解釋一下這個問題。 –

回答

1

爲了使標記圖標中心allingned使用地錨。

_marker1 = [[GMSMarker alloc] init]; 
_marker1.position = CLLocationCoordinate2DMake(12.9716, 77.5946); 
_marker1.title = @"sydney"; 
_marker1.groundAnchor = CGPointMake(0.2, 0.9); 
_marker1.appearAnimation = kGMSMarkerAnimationPop; 
_marker1.appearAnimation = kGMSMarkerAnimationPop; 
_marker1.icon = [UIImage imageNamed:@"Flag Filled -50.png"]; 

因人而異地錨點,使其中心

+0

沒有它的不工作。我想以這種方式放置一個標記,所以多段線總是繪製水平線 – Prabhat

+0

標記線放置不工作或水平繪製多段線不工作。可以解釋 –

+0

多段線水平繪製 – Prabhat

0

臥式多段線,純粹是依賴於緯度值。如果兩個位置緯度值相同,則多邊形線是水平的。 poly line horizontallu

_path = [GMSMutablePath path]; 
[_path addLatitude:12.9716 longitude:77.5946]; // bangalore 
[_path addLatitude:12.9716 longitude:78.0]; // tumkur 


_marker1 = [[GMSMarker alloc] init]; 
_marker1.position = CLLocationCoordinate2DMake(12.9716, 77.5946); 
_marker1.title = @"Bangalore"; 
_marker1.groundAnchor = CGPointMake(0.2, 0.9); 
_marker1.appearAnimation = kGMSMarkerAnimationPop; 
_marker1.appearAnimation = kGMSMarkerAnimationPop; 
_marker1.icon = [UIImage imageNamed:@"Flag Filled -50.png"]; 
_marker1.snippet = @"India"; 
_marker1.map = _mapView; 

_marker2 = [[GMSMarker alloc] init]; 
_marker2.position = CLLocationCoordinate2DMake(12.9716, 78.0); 
_marker2.title = @"Tumkur"; 
_marker2.groundAnchor = CGPointMake(0.3, 0.9); 
_marker2.snippet = @"India"; 
_marker2.icon = [UIImage imageNamed:@"Flag Filled -50.png"]; 
_marker2.map = _mapView; 
_polyline = [GMSPolyline polylineWithPath:_path]; 
_polyline.strokeColor = [UIColor blueColor]; 
_polyline.strokeWidth = 1.f; 
_polyline.path = _path; 
_polyline.map = _mapView;