Ios 在GoogleMapSDK上放置标记
我成功地在两点之间绘制了多段线。但我想把源点放在地图的左侧,目标点放在地图的右侧,并在它们之间水平画一条线 任何想法都值得赞赏Ios 在GoogleMapSDK上放置标记,ios,objective-c,google-maps-sdk-ios,Ios,Objective C,Google Maps Sdk Ios,我成功地在两点之间绘制了多段线。但我想把源点放在地图的左侧,目标点放在地图的右侧,并在它们之间水平画一条线 任何想法都值得赞赏 - (void)addMarkerOnMap { NSArray* arrMarkerData = @[ @{@"icon":[UIImage imageNamed:@"blue"], @"position":[[CLLocation alloc]initWithLatitude:self.pickupAddCoo
- (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");
}
}];
}
要使标记图标居中对齐,请使用地锚
_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"];
改变地面锚定点使其居中水平多线完全取决于纬度值。如果两个位置纬度值相同,则多边形线是水平的。
您可以使用两个图像图标来标记(一个用于源,另一个用于目标)。我只想显示从左到右的多段线。然后你能简单地解释一下问题是什么。源标记总是在地图的左侧,目的地总是在右侧。希望这是有意义的。添加地锚:CLLocationCoordinate2D位置=CLLocationCoordinate2DMake(51.5,-0.127);CLLocationDegrees=90;GMSMarker*london=[GMSMarker marker with position:position];london.groundAnchor=CGPointMake(0.5,0.5);伦敦。旋转=度;london.map=mapView;不,它不起作用。我想用这种方式放置一个标记,因此,多段线始终绘制水平标记放置不起作用或水平绘制多段线不起作用。您能否解释多段线绘制水平多段线取决于您指定给GMSmutablepath的点。如果您指定两个横向多段线,则多段线是水平的。请在问题中添加有助于回答的代码段你的问题准确无误。
_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;