iOS 解析 GeoPoints 和 MapBox 形状

标签 ios parse-platform mapbox

所以我想知道如何使用 MapBox 检索 Parse 坐标和绘制形状。

我可以检索坐标并在 map 上单独绘制它们(使用 PARSE ):

PFQuery *locationQuery = [PFQuery queryWithClassName:@"Location"];
[locationQuery whereKeyExists:@"location"];
locationQuery.cachePolicy = kPFCachePolicyNetworkElseCache;
[locationQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"Successfully retrieved %lu scores.", (unsigned long)objects.count);
        NSLog(@"Object is %@ and %@", [objects objectAtIndex:0],[objects objectAtIndex:1]);

        for (PFObject *gp in objects) {

            //How to get PFGeoPoint and then a location out of an object
            PFGeoPoint *location = [gp objectForKey:@"location"];

            NSLog(@"Hi there my name is: %f", location.latitude);

            CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(location.latitude, location.longitude);

            //This is how to populate the data with a title
            NSString *title = [NSString stringWithFormat:@"%@", gp.createdAt];

            RMPointAnnotation *annotation3 = [[RMPointAnnotation alloc] initWithMapView:mapView coordinate:coordinate andTitle:title];
            [mapView addAnnotation:annotation3];

        }

    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

向 map 添加形状(使用 MapBox )也是可行的:

//Line for streets location arrays, etc MapBox
    NSArray *locations = [NSArray arrayWithObjects:[[CLLocation alloc] initWithLatitude:-33.980852 longitude:151.072498],
                          [[CLLocation alloc] initWithLatitude:-33.981769 longitude:151.072300],
                          [[CLLocation alloc] initWithLatitude:-33.982018 longitude:151.072257],
                          [[CLLocation alloc] initWithLatitude:-33.982187 longitude:151.072225], nil, nil];

    RMAnnotation *annoation43 = [[RMAnnotation alloc] initWithMapView:mapView coordinate:((CLLocation *)[locations

objectAtIndex:0]).coordinate andTitle:@"Hola biatches!"];

    annoation43.userInfo = locations;
    [annoation43 setBoundingBoxFromLocations:locations];
    [mapView addAnnotation:annoation43];
    NSLog(@"It is working Dora!");

-(RMMapLayer *)mapView:(RMMapView *)mapViewer layerForAnnotation:(RMAnnotation *)annotation {

    if (annotation.isUserLocationAnnotation)
        return nil;

    RMShape *shape = [[RMShape alloc] initWithView:mapView];

    //Line dashes and colours and widths, etc
    shape.lineColor = [UIColor orangeColor];
    shape.lineWidth = 4.0;
    shape.scaleLineWidth = YES;
    shape.scaleLineDash = YES;
    shape.lineDashLengths = [NSArray arrayWithObjects:[NSNumber numberWithInt:4], [NSNumber numberWithInt:6], nil];
    shape.lineDashPhase = 3.0f;



    for (CLLocation *location in (NSArray *)annotation.userInfo)
        [shape addLineToCoordinate:location.coordinate];

    return shape;


}

我想知道如何让 MapBox 从这些坐标绘制形状?我已经进行了几次尝试,但一无所获,因此,如果有人比我有更好的头脑,我们将不胜感激。如果您需要更多信息,请告诉我。

最佳答案

我想通了 - 我尝试的解决方案很好 - 我在循环内初始化数组,所以它每次都重新创建数组,所以覆盖每个新坐标并尝试仅使用一个坐标绘制形状.

PFQuery *locationQuery2 = [PFQuery queryWithClassName:@"Location"];
    [locationQuery2 whereKeyExists:@"location"];
    locationQuery2.limit = 4;
    locationQuery2.cachePolicy = kPFCachePolicyNetworkElseCache;
    [locationQuery2 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // The find succeeded.
            NSLog(@"Successfully retrieved %lu scores.", (unsigned long)objects.count);
            NSLog(@"Object is %@ and %@", [objects objectAtIndex:0],[objects objectAtIndex:1]);
            NSMutableArray *locations = [[[NSMutableArray alloc] init] mutableCopy];

            for (PFObject *gp in objects) {

                //How to get PFGeoPoint and then a location out of an object
                PFGeoPoint *location = [gp objectForKey:@"location"];

                NSLog(@"Hi there my name is not: %f", location.latitude);

                CLLocation *coordinate = [[CLLocation alloc] initWithLatitude:location.latitude longitude:location.longitude];

                //Line for streets location arrays, etc MapBox
                [locations addObject:coordinate];

                RMAnnotation *annoation43 = [[RMAnnotation alloc] initWithMapView:mapView coordinate:((CLLocation *)[locations objectAtIndex:0]).coordinate andTitle:@"Hola biatches!"];

                annoation43.userInfo = locations;
                [annoation43 setBoundingBoxFromLocations:locations];
                [mapView addAnnotation:annoation43];
                NSLog(@"It is working Dora!");


                NSLog(@"Yeah its is: %@", locations);
            }

        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];

关于iOS 解析 GeoPoints 和 MapBox 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24056782/

相关文章:

ios swift 创建圆形个人资料图像,如 twitter、instagram、

android - c++11线程或boost.thread支持android ios

ios - 未隐式定义关联类型的通用协议(protocol)

ios - UIScrollView性能问题

java - Android解析查询2个类

parse-platform - 如何在 Parse.com 中为表指定外键

iOS - 解析当前用户提取不工作

ios - 如何在 iOS 版 MapBox 中显示比例尺?

javascript - 使用 Javascript 将 url 插入 Django 模板

ios - MapBox:在注释上绘制的 MGLineStyleLayer