首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS解析GeoPoints & MapBox形状

iOS解析GeoPoints & MapBox形状
EN

Stack Overflow用户
提问于 2014-06-05 09:42:28
回答 1查看 711关注 0票数 0

因此,我想知道如何检索解析坐标,并使用MapBox绘制形状。

我可以检索坐标并(使用解析)在地图上精细地绘制它们:

PFQuery *locationQuery = PFQuery queryWithClassName:@"Location";locationQuery其中location:@“location”;locationQuery.cachePolicy = kPFCachePolicyNetworkElseCache;[locationQuery findObjectsInBackgroundWithBlock:^(NSArray *objects,NSError *error) { if (!error) { //查找成功。NSLog(@“成功检索到%lu得分”,(无符号长)objects.count);NSLog(“object is %@和%@",objects objectAtIndex:0,objects objectAtIndex:1);for (PFObject *gp in object){//如何获取PFGeoPoint,然后从对象PFGeoPoint *location = gp objectForKey:@@”location“;NSLog(”Hi那里我的名字是:%f",location.latitude);CLLocationCoordinate2D坐标= CLLocationCoordinate2DMake(location.latitude,location.longitude);//这是如何用标题NSString *title = NSString stringWithFormat:@"%@",gp.createdAt来填充数据;RMPointAnnotation *注释3= [RMPointAnnotation alloc initWithMapView:mapView坐标:坐标和title :title];mapView addAn表示法:注释3;}NSLog的{ //日志详细信息(@“error:%@ %@",error,error userInfo);}];

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

//用于街道位置数组等MapBox NSArray *locations = [NSArray arrayWithObjects:[CLLocation alloc initWithLati经:-33.980852经度:151.072498],[CLLocation alloc initWithLati经:-33.981769经度:151.072300],[CLLocation alloc initWithLati经:-33.982018经度:151.072257],[CLLocation alloc initWithLatitude:-33.982187经度:151.072225],nil,nil];RMAnnotation *disunation43= [RMAnnotation alloc initWithMapView:mapView坐标:((CLLocation*)位置“ objectAtIndex:0).coordinate和:@“你好!” annoation43:(RMMapLayer *) mapView :(RMMapView *)mapViewer layerForAnnotation:(RMAnnotation *)注释{ if (annotation.isUserLocationAnnotation)返回零;RMShape *shape = [RMShape alloc initWithView:mapView];//Line、颜色和宽度等shape.lineColor = UIColor orangeColor;shape.lineWidth = 4.0;shape.scaleLineWidth = YES;shape.scaleLineDash = YES;shape.lineDashLengths = [NSArray arrayWithObjects:NSNumber NSArray:4,NSNumber numberWithInt:6,nil];shape.lineDashPhase = 3.0f;for (CLLocation *location in (NSArray *)annotation.userInfo) shape addLineToCoordinate:location.coordinate;返回形状;

我想知道如何让MapBox从这些坐标中画一个形状?我做了几次尝试,但没有取得任何进展,所以比我头脑更好的人会非常感激的。如果你需要更多的信息,请告诉我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-06 08:17:21

我想出了答案--我尝试的解决方案很好--我在循环中初始化数组,所以它每次都在重新创建数组,因此覆盖了每个新的坐标,并试图只使用一个坐标绘制一个形状。

代码语言:javascript
复制
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]);
        }
    }];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24056782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档