2013-03-10 39 views
8

EDIT: Điều này bây giờ là một lỗi xác nhận với this SDKSDK Google Maps iOS: Làm thế nào để tôi có được tọa độ vĩ độ và kinh độ chính xác từ chế độ hiển thị của máy ảnh?

Tôi đang sử dụng phiên bản 1.1.1.2311 của Google Maps dành cho iOS SDK, và tôi đang tìm để tìm các vĩ độ và kinh độ bounding cho bản đồ hiển thị trên màn hình.

Tôi đang sử dụng đoạn mã sau để cho tôi biết những gì chiếu hiện nay là:

NSLog(@"\n%@,%@\n%@,%@\n%@,%@\n%@,%@\n", 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.farLeft.latitude], 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.farLeft.longitude], 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.farRight.latitude], 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.farRight.longitude], 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.nearLeft.latitude], 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.nearLeft.longitude], 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.nearRight.latitude], 
    [NSNumber numberWithDouble:mapView.projection.visibleRegion.nearRight.longitude]); 

Từ đọc các tiêu đề, có vẻ như nó có thể không được cập nhật khi di chuyển camera. Hội chợ đủ ...

/** 
* The GMSProjection currently used by this GMSMapView. This is a snapshot of 
* the current projection, and will not automatically update when the camera 
* moves. The projection may be nil while the render is not running (if the map 
* is not yet part of your UI, or is part of a hidden UIViewController, or you 
* have called stopRendering). 
*/ 

Tuy nhiên, nó dường như cập nhật mỗi lần phương pháp đại biểu được gọi, vì vậy tôi đã cố gắng để âm mưu tọa độ để kiểm tra chúng ...

Đối với sau trên điện thoại của tôi:

my app's current projection

Đầu ra của NSLog từ trên cao mang lại cho tôi những điều sau đây:

37.34209003645947,-122.0382353290915 
37.34209003645947,-122.010769508779 
37.30332095984257,-122.0382353290915 
37.30332095984257,-122.010769508779 

Khi âm mưu những tọa độ sử dụng this tôi nhận được một dự báo mà dường như tắt:

actual projection

Những tọa độ là nhất quán trên ra mắt ứng dụng mà dẫn tôi để tin rằng tôi hoặc liên tục làm điều gì đó sai, tôi hiểu lầm những gì visibleRegion là, hoặc tôi đã phát hiện ra một lỗi. Bất cứ ai quan tâm để giúp tôi tìm ra nó là ai?

+0

Bị mắc kẹt trong cùng một vấn đề. Hãy cho tôi biết nếu tìm thấy bất kỳ giải pháp nào. cảm ơn – Mangesh

Trả lời

2

Giải pháp là tải xuống phiên bản SDK mới nhất (1.2 tại thời điểm viết bài này) khi sự cố đã được khắc phục.

Từ các ghi chú 1.2 phát hành:

vấn đề giải quyết: - visibleRegion giờ đây báo cáo khu vực có kích thước chính xác trên các thiết bị Retina

Tải here.

-3

Có lẽ bạn cung cấp cho các vị trí quản lý về tính chính xác sai ..

Cố gắng tăng nó:

locationMgr.desiredAccuracy = kCLLocationAccuracyBest; 

Pin được thoát moreyy

+0

Tôi không tin như vậy. SDK xử lý điều đó. – andybons

11

Để có được vĩ độ và kinh độ bounding bạn phải thực hiện các bước sau:

GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithRegion:self.googleMapsView.projection.visibleRegion]; 

CLLocationCoordinate2D northEast = bounds.northEast; 
CLLocationCoordinate2D northWest = CLLocationCoordinate2DMake(bounds.northEast.latitude, bounds.southWest.longitude); 
CLLocationCoordinate2D southEast = CLLocationCoordinate2DMake(bounds.southWest.latitude, bounds.northEast.longitude); 
CLLocationCoordinate2D southWest = bounds.southWest; 

Quan trọng nhất s Robert

+0

Tôi e rằng tôi nhận được kết quả tương tự. – andybons

1

Dường như các tọa độ kinh độ và vĩ độ bạn đang in ra và vẽ theo cách thủ công có thể bị cắt bớt một chút/bị cắt ngắn. % f mặc định chỉ in ra 6 chữ số thập phân.

Dưới đây là một câu hỏi liên quan có thể giúp:

How to print a double with full precision on iOS?

+0

Không. Ngay cả khi tăng độ chính xác bằng cách sử dụng NSNumber cho phép chiếu sau: http://imgur.com/sQBUjSi Tôi nhận được kết quả này: http://imgur.com/ZW5oB1I – andybons

+0

Cập nhật câu hỏi để phản ánh đề xuất chính xác của bạn. Cảm ơn. – andybons

6

tôi thấy vấn đề của bạn here. Hy vọng rằng họ khắc phục vấn đề này trong bản cập nhật tiếp theo.

Nhưng bây giờ chúng ta có thể lấy vùng khả kiến ​​thực như thế này:

CGPoint topLeftPoint = CGPointMake(0, 0); 
    CLLocationCoordinate2D topLeftLocation = 
    [_mapView.projection coordinateForPoint: topLeftPoint]; 

    CGPoint bottomRightPoint = 
    CGPointMake(_mapView.frame.size.width, _mapView.frame.size.height); 
    CLLocationCoordinate2D bottomRightLocation = 
    [_mapView.projection coordinateForPoint: bottomRightPoint]; 

    CGPoint topRightPoint = CGPointMake(_mapView.frame.size.width, 0); 
    CLLocationCoordinate2D topRightLocation = 
    [_mapView.projection coordinateForPoint: topRightPoint]; 

    CGPoint bottomLeftPoint = 
    CGPointMake(0, _mapView.frame.size.height); 
    CLLocationCoordinate2D bottomLeftLocation = 
    [_mapView.projection coordinateForPoint: bottomLeftPoint]; 

    GMSVisibleRegion realVisibleRegion; 
    realVisibleRegion.farLeft = topLeftLocation; 
    realVisibleRegion.farRight = topRightLocation; 
    realVisibleRegion.nearLeft = bottomLeftLocation; 
    realVisibleRegion.nearRight = bottomRightLocation; 

    [self drawPolylineWithGMSVisibleRegion:realVisibleRegion color:[UIColor redColor] width:10.0f forMap:mapView]; 

Vẽ phương pháp polyline:

- (void)drawPolylineWithGMSVisibleRegion:(GMSVisibleRegion)visibleRegion 
           color:(UIColor*)color 
           width:(double)width 
           forMap:(GMSMapView*)mapView{ 
    GMSPolylineOptions *rectangle = [GMSPolylineOptions options]; 
    rectangle.color = color; 
    rectangle.width = width; 
    GMSMutablePath *path = [GMSMutablePath path]; 
    [path addCoordinate:visibleRegion.nearRight]; 
    [path addCoordinate:visibleRegion.nearLeft]; 
    [path addCoordinate:visibleRegion.farLeft]; 
    [path addCoordinate:visibleRegion.farRight]; 
    [path addCoordinate:visibleRegion.nearRight]; 
    rectangle.path = path; 
    [mapView addPolylineWithOptions:rectangle]; 
} 

Nó hoạt động ngay cả đối với bản đồ với vòng bi và góc không mặc định.

+0

Mã này thực tế dưới phiên bản 1.3 sdk. Tham khảo phiên bản mới: https://developers.google.com/maps/documentation/ios/reference/index – kaspartus

Các vấn đề liên quan