我成功地在两点之间绘制折线。但我想将源点放在 map 的左侧,将目标点放在 map 的右侧,并在它们之间水平画线。
非常感谢任何想法。
- (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");
}
}];
}
最佳答案
要使标记图标居中,请使用 Ground Anchor。
_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"];
改变地面 anchor 使其居中
关于ios - 在 GoogleMapSDK 上放置标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36762345/