【问题标题】:NSLog detect updating current location in MKPolygonNSLog 检测更新 MKPolygon 中的当前位置
【发布时间】:2013-08-22 13:17:35
【问题描述】:

这里是菜鸟。我已经阅读了如何检测 MKPolygon 中的一个点,但我在实现它时遇到了困难——它可能与我正在检查用户位置的代码部分有关……我不是即使确定它是否一直在检查。无论如何,这是相关代码:

- (void)locationManager:(CLLocationManager *)manager
  didUpdateLocations:(NSArray *)locations {
self.current = [locations lastObject];
NSLog(@"lat%f - lon%f", self.current.coordinate.latitude, self.current.coordinate.longitude);
NSLog(@"%@", self.mapCIIP); }

以后

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay{
if([overlay isKindOfClass:[MKPolygon class]]){
    MKPolygonRenderer *view = [[MKPolygonRenderer alloc] initWithOverlay:overlay];
    view.lineWidth=1;
    view.strokeColor=[UIColor blueColor];
    view.fillColor=[[UIColor blueColor] colorWithAlphaComponent:0.5];


    return view;
    CLLocationCoordinate2D mapCoordinate = CLLocationCoordinate2DMake(self.current.coordinate.latitude, self.current.coordinate.longitude);

    MKMapPoint mapPoint = MKMapPointForCoordinate(mapCoordinate);
    if (CLLocationCoordinate2DIsValid(mapCoordinate)) {
        NSLog(@"Coordinate valid");
    } else {
        NSLog(@"Coordinate invalid");
    }

    CGPoint polygonViewPoint = [view pointForMapPoint:mapPoint];


    if ( CGPathContainsPoint(view.path, NULL, polygonViewPoint, NO) ) {
        self.mapCIIP = @"TRUE";
    }
    else {
        self.mapCIIP = @"false";
    };


}
return nil; }

我模拟了 Xcode 中的不同位置,它在我的 iPhone 上运行,虽然更新了纬度/经度,但它并没有给我想要的我所绘制的多边形中的真/假。在某一时刻,它显示为全部真实,但现在在 NSLog 中全部为(空)。谢谢!

【问题讨论】:

    标签: ios objective-c mapkit cllocationmanager mkpolygon


    【解决方案1】:

    在您的函数中,它返回view,因此无法访问设置mapCIIP 的代码。

    【讨论】:

    • 我将return view 移动到if([overlay isKindOfClass:[MKPolygon class]]) 的最末端,但是当我将当前位置更改为多边形内部或外部时,我仍然没有显示开关——都是@987654325 @
    • 我看不到任何关于MKPolygonRenderer 是什么或它的pointForMapPoint 函数应该做什么的记录,尽管我可以猜到。你能链接到它的一些文档吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    相关资源
    最近更新 更多