Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS无法添加多边形标记-仅绘制多段线-未添加标记_Ios_Google Maps_Google Maps Markers_Google Maps Sdk Ios_Polyline - Fatal编程技术网

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

IOS无法添加多边形标记-仅绘制多段线-未添加标记,ios,google-maps,google-maps-markers,google-maps-sdk-ios,polyline,Ios,Google Maps,Google Maps Markers,Google Maps Sdk Ios,Polyline,我目前正在开发一个模块,该模块可以显示标记和多段线,以显示机器人可以从位置a到位置B的路线。当涉及到通过长触摸添加标记和线时,它只显示绘制和添加的GMSPolylines。但是,没有添加任何标记。请告诉我是否可以分别在两者之间绘制标记和多段线 下面是我的代码 @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after load

我目前正在开发一个模块,该模块可以显示标记和多段线,以显示机器人可以从位置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
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
array=[[NSMutableArray alloc]init];
//创建一个GMSCameraPosition,告诉地图显示
//缩放级别6时的坐标-33.86151.20。
GMSCameraPosition*摄像机=[GMSCameraPosition摄像机,纬度:22.2855200
经度:114.1576900
缩放:12];
地图视图=[GMSMapView地图WithFrame:CGRectZero相机:相机];
mapView_.delegate=self;
mapView_u2;.myLocationEnabled=是;
mapView.settings.compassButton=是;
mapView_979;.settings.myLocationButton=是;
//mapView_.delegate=self;
self.view=mapView;
//在地图的中心创建一个标记。
GMSMarker*标记=[[GMSMarker alloc]init];
marker.position=CLLocationCoordinate2DMake(22.2855200,114.1576900);
marker.title=@“我的位置”;
marker.snippet=@“HK”;
marker.map=mapView;
}
-(无效)添加标记
{
//[地图视图清除];
如果([数组计数]>0){
GMSMutablePath*path=[GMSMutablePath];
对于(int i=0;i<[数组计数];i++){
CLLocationCoordinate2D位置=CLLocationCoordinate2DMake(11.11123.123);
GMSMarker*marker=[GMSMarker marker with position:position];
marker.position=位置;
marker.title=@“设计”;
NSString*tmpLat=[[NSString alloc]initWithFormat:@“%f”,位置.纬度];
NSString*tmpLong=[[NSString alloc]initWithFormat:@“%f”,position.longitude];
marker.snippet=[NSString stringWithFormat:@“%@%@”,tmpLat,tmpLong];
UIColor*颜色;
检查点*cp=[array objectAtIndex:i];
[路径添加纬度:cp.getLatitude经度:cp.getLatitude];
GMSPolyline*polyline=[GMSPolyline polylineWithPath:path];
polyline.geodesic=是;
折线.strokeWidth=10.f;
如果(cp.getState==1){
//绿色的
颜色=[UIColor colorWithHue:.2饱和度:1.f亮度:1.f alpha:1.0f];
polyline.strokeColor=[UIColor greenColor];
}否则{
颜色=[UIColor colorWithHue:1.饱和度:1.f亮度:1.f alpha:1.0f];
polyline.strokeColor=[UIColor redColor];
}
marker.icon=[GMSMarker markerImageWithColor:color];
marker.map=mapView;
polyline.map=mapView;
}
}
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(无效)地图视图:(GMSMapView*)地图视图未长按坐标:(CLLocationCoordinate2D)坐标{
//GMSMarker*marker3=[[GMSMarker alloc]init];
//marker3.position=坐标;
//marker3.title=@“设计”;
//NSString*tmpLat=[[NSString alloc]initWithFormat:@“%f”,坐标纬度];
//NSString*tmpLong=[[NSString alloc]initWithFormat:@“%f”,坐标经度];
//marker3.snippet=[NSString stringWithFormat:@“%@%@”,tmpLat,tmpLong];
//    
//marker3.map=mapView;
检查点*myCar=[[CheckPoints alloc]init];
[myCar设置状态:0];
[myCar设置纬度:坐标纬度];
[myCar设置经度:坐标经度];
NSString*文本值=@“设计”;
[myCar setDesp:文本值];
NSLog(@“%d”,myCar.getState);
NSLog(@“%f”,myCar.getLatitude);
NSLog(@“%f”,myCar.getLongitude);
NSLog(@“%@”,myCar.getDesp);
[数组addObject:myCar];
检查点*lastChk=array.lastObject;
对于(int i=0;i<[数组计数];i++){
检查点*current=[array objectAtIndex:i];
if(current.getLatitude!=lastChk.getLatitude&¤t.getLength!=lastChk.getLength){
[当前设置状态:1];
NSString*previousTitle=[NSString stringWithFormat:@“%@%@”,“Checkpoint”,“NSString stringWithFormat:@“%i”,i]”;
[current setDesp:previousTitle];
}
}
[自我添加标记];
[ToastView show ToastParentView:self.view with text:@“真是太棒了!”with duaration:5.0];
}
@结束

看起来您正在重复添加相同的标记

for (int i = 0; i < [array count]; i++) {
        CLLocationCoordinate2D position = CLLocationCoordinate2DMake(11.11 , 123.123);
        GMSMarker *marker = [GMSMarker markerWithPosition:position];
for(int i=0;i<[数组计数];i++){
CLLocationCoordinate2D位置=CLLocationCoordinate2DMake(11.11123.123);
GMSMarker*marker=[GMSMarker marker with position:position];

…硬编码点。

看起来您正在重复添加相同的标记

for (int i = 0; i < [array count]; i++) {
        CLLocationCoordinate2D position = CLLocationCoordinate2DMake(11.11 , 123.123);
        GMSMarker *marker = [GMSMarker markerWithPosition:position];
for(int i=0;i<[数组计数];i++){
CLLocationCoordinate2D位置=CLLocationCoordinate2DMake(11.11123.123);
GMSMarker*marker=[GMSMarker marker with position:position];

…硬编码点。

您从不使用路径点的坐标,而是使用硬编码的坐标:

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(11.11 , 123.123);
使用路径

CLLocationCoordinate2D position = [path coordinateAtIndex:i];

您从不使用路径点的坐标,而是使用硬编码的坐标:

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(11.11 , 123.123);
使用路径

CLLocationCoordinate2D position = [path coordinateAtIndex:i];

self.googleMapsView是谷歌地图视图

示例:self.getDirections(“26.9211992,75.8185761”,目的地:“26.8472496,75.7691909”,航路点:[“26.8686811,75.7568383],旅行模式:无,完成处理程序:无)

示例:谷歌方向链接

let baseURLGeocode=”https://maps.googleapis.com/maps/api/geocode/json?"
让我们看看方向