ios - 在 GoogleMapSDK 上放置标记

标签 ios objective-c google-maps-sdk-ios

我成功地在两点之间绘制折线。但我想将源点放在 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/

相关文章:

ios - Xamarin Forms,当我在应用程序商店(Testflight)上发布我的应用程序时,标签字体大小在不同的 iPhone 6s 设备上不同

ios - 如何找到Google Maps Path的长度

ios - 谷歌地图自定义夜间模式 iOS

objective-c - 如何将.nib加载到 View 中?

swift - 移动 GMSPanoramaView 堆积内存

ios - 将现有的 sencha touch Web 应用程序移植到 ios native 应用程序

iphone - 比较从相机拍摄的图像与现有图像

ios - 如何删除一个单元格并将其放入另一个索引中?

objective-c - 如何检测 NSPanel 何时因失去焦点而关闭?例如。用户在 NSPanel 外部单击(窗口?)

iphone - 如何使用 NSMutableArray 中的列名列表在 sqlite3 中创建表