1

I am using Google SDK for my base maps. I can see my layers from GeoServer overlayed on Google maps but I am stuck at the getfeatureinfo request.

(void) mapView: (GMSMapView * ) mapView1 didTapAtCoordinate: (CLLocationCoordinate2D) coordinate {
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
    NSLog(@"Latitude= %f lonitude = %f", coordinate.latitude, coordinate.longitude);
    GMSMarker * marker = [GMSMarker markerWithPosition: position];
    point = [mapView1.projection pointForCoordinate: marker.position];
    //ankita.dutta@hardcastlegis.com
    GMSCoordinateBounds * bounds = [
        [GMSCoordinateBounds alloc] initWithCoordinate: coordinate coordinate: coordinate
    ];
    NSLog(@"Bounds.minx = %f,%f,%f,%f", bounds.southWest.longitude, bounds.northEast.latitude, bounds.northEast.longitude, bounds.southWest.latitude);
    NSLog(@"Pointer: %d, %d", [
        [NSNumber numberWithFloat: point.x] intValue
    ], [
        [NSNumber numberWithFloat: point.y] intValue
    ]);
    GMSVisibleRegion region;
    region = mapView.projection.visibleRegion;
    GMSCoordinateBounds * bounds1 = [
        [GMSCoordinateBounds alloc] initWithRegion: region
    ];
    NSLog(@"Bounds.minx = %.15f,%.15f,%.15f,%.15f", bounds1.southWest.longitude, bounds1.northEast.latitude, bounds1.northEast.longitude, bounds1.southWest.latitude);
    [self getInfo: [
        [NSNumber numberWithFloat: point.x] intValue
    ]: [
        [NSNumber numberWithFloat: point.y] intValue
    ]: bounds1.southWest.longitude: bounds1.northEast.latitude: bounds1.northEast.longitude: bounds1.southWest.latitude];
}
(void) getInfo: (int) xValue: (int) yValue: (double) bboxLMin: (double) bboxLMax: (double) bboxRMin: (double) bboxTMax {
    // [self showLoadingView:YES];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
        //2048x1536
        NSMutableURLRequest * request = [
            [NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: [NSString stringWithFormat: @"http://ipaddress/geoserver/wms?service=WMS&version=1.1.1&srs=EPSG:4326&bbox=%.15f,%.15f,%.15f,%.15f&styles=&&buffer=40&info_format=application/json&request=GetFeatureInfo&layers=gidc:plots_category_wise&query_layers=gidc:plots_category_wise&width=%d&height=%d&x=%d&y=%d", bboxLMin, bboxLMax, bboxRMin, bboxTMax, 1536, 2048, xValue , yValue ]]
        ];
        NSURLSession * session = [NSURLSession sharedSession];
        [
            [session dataTaskWithRequest: request completionHandler: ^ (NSData * data, NSURLResponse * response, NSError * error) {
                if (data != NULL) {
                    dispatch_async(dispatch_get_main_queue(), ^ {
                        //[self showLoadingView:NO];
                        NSMutableDictionary * listDict = [NSJSONSerialization JSONObjectWithData: data options: 0 error: nil];
                        NSMutableArray * dataArr = [
                            [listDict valueForKey: @"features"] valueForKey: @"properties"
                        ];
                        [self response: dataArr];
                    });
                }
            }] resume
        ];
    });
}
  • what happens? what doesn't work? why are you multiplying the x and y values by 2? – Ian Turton Feb 16 '17 at 8:51
  • @iant actually iPhone size that is width and height are in points not in pixels so to convert points in pixels multiplying it by 2. Actually on click I am getting data but it is wrong means if I click on layer one it returns me data of layer two – amar Feb 16 '17 at 9:06
  • please update your question using the edit button – Ian Turton Feb 16 '17 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.