gpt4 book ai didi

IOS 无法添加多边形标记 仅绘制折线 未添加标记

转载 作者:行者123 更新时间:2023-11-28 18:33:08 24 4
gpt4 key购买 nike

我目前正在开发可以显示标记和折线的模块,以显示机器人可以从位置 A 到位置 B 的路线。当通过长按添加标记和线时,它只显示 GMSPolylines 被绘制和添加。但是,没有添加任何标记。请告诉我是否可以分别在两者之间绘制标记和多边形?

下面是我的代码

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

array = [[NSMutableArray alloc] init];
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:22.2855200
longitude:114.1576900
zoom:12];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.delegate = self;

mapView_.myLocationEnabled = YES;
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
// mapView_.delegate = self;
self.view = mapView_;

// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(22.2855200, 114.1576900);
marker.title = @"My place";
marker.snippet = @"HK";
marker.map = mapView_;


}


- (void)addMarkers
{
// [mapView_ clear];
if([array count] > 0){
GMSMutablePath *path = [GMSMutablePath path];
for (int i = 0; i < [array count]; i++) {
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(11.11 , 123.123);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.position = position;
marker.title = @"Desitnation";
NSString *tmpLat = [[NSString alloc] initWithFormat:@"%f", position.latitude];
NSString *tmpLong = [[NSString alloc] initWithFormat:@"%f", position.longitude];
marker.snippet = [NSString stringWithFormat:@"%@ %@", tmpLat,tmpLong];

UIColor *color;
CheckPoints *cp = [array objectAtIndex:i];
[path addLatitude:cp.getLatitude longitude:cp.getLongitude];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.geodesic = YES;
polyline.strokeWidth = 10.f;
if (cp.getState ==1) {
// Green
color = [UIColor colorWithHue:.2 saturation:1.f brightness:1.f alpha:1.0f];
polyline.strokeColor = [UIColor greenColor];
} else {
color = [UIColor colorWithHue:1. saturation:1.f brightness:1.f alpha:1.0f];
polyline.strokeColor = [UIColor redColor];
}
marker.icon = [GMSMarker markerImageWithColor:color];
marker.map = mapView_;
polyline.map = mapView_;
}

}
}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void) mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate{
// GMSMarker *marker3 = [[GMSMarker alloc] init];
// marker3.position = coordinate;
// marker3.title = @"Desitnation";
// NSString *tmpLat = [[NSString alloc] initWithFormat:@"%f", coordinate.latitude];
// NSString *tmpLong = [[NSString alloc] initWithFormat:@"%f", coordinate.longitude];
// marker3.snippet = [NSString stringWithFormat:@"%@ %@", tmpLat,tmpLong];
//
// marker3.map = mapView_;


CheckPoints *myCar=[[CheckPoints alloc] init];
[myCar setState:0];
[myCar setLatitude:coordinate.latitude];
[myCar setLongitude:coordinate.longitude];
NSString* theTextValue = @"Desitnation";
[myCar setDesp:theTextValue];

NSLog( @"%d", myCar.getState );
NSLog( @"%f", myCar.getLatitude);
NSLog( @"%f", myCar.getLongitude );
NSLog( @"%@", myCar.getDesp );

[array addObject:myCar];
CheckPoints *lastChk = array.lastObject;
for (int i = 0; i < [array count]; i++) {
CheckPoints *current = [array objectAtIndex:i];
if(current.getLatitude != lastChk.getLatitude && current.getLongitude != lastChk.getLongitude){
[current setState:1];
NSString* previousTitle = [NSString stringWithFormat:@"%@%@", @"Checkpoint" ,[NSString stringWithFormat:@"%i", i]];
[current setDesp:previousTitle];
}
}
[self addMarkers];
[ToastView showToastInParentView:self.view withText:@"What a toast!" withDuaration:5.0];


}

@end

最佳答案

看起来你在重复添加相同的标记......

for (int i = 0; i < [array count]; i++) {
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(11.11 , 123.123);
GMSMarker *marker = [GMSMarker markerWithPosition:position];

...硬编码点。

关于IOS 无法添加多边形标记 仅绘制折线 未添加标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24134661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com