2013-03-10 12 views
8

EDIT: Questo è ora un bug confermato con this SDKGoogle Maps SDK per iOS: come ottenere precise coordinate di latitudine e longitudine dalla Visione visibile di una telecamera?

sto usando la versione 1.1.1.2311 di Google Maps per iOS SDK, e sto cercando di trovare la delimitazione coordinate di latitudine e longitudine per la mappa visibile sullo schermo.

Sto utilizzando il seguente codice di dirmi che cosa la proiezione corrente è:

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]); 

Dalla lettura delle intestazioni, sembra che non può essere aggiornato quando la telecamera si muove. Fiera abbastanza ...

/** 
* 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). 
*/ 

Ma, sembra di aggiornare ogni volta che il metodo delegato è chiamato, quindi ho cercato di tracciare le coordinate per metterli alla prova ...

Per il seguente sul mio telefono:

my app's current projection

l'uscita del NSLog dall'alto mi dà il seguente:

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

Nel tracciare quelle coordinate utilizzando this ottengo una proiezione che sembra fuori:

actual projection

Queste coordinate sono coerenti tra lanci di app che mi porta a credere che sto sia costantemente facendo qualcosa di sbagliato, io sono equivoco a cosa sia visibleRegion o ho scoperto un bug. Qualcuno dovrebbe aiutarmi a capire qual è?

+0

Bloccato nello stesso numero. Fammi sapere se ho trovato qualche soluzione. grazie – Mangesh

risposta

2

La soluzione è scaricare l'ultima versione dell'SDK (1.2 al momento della stesura di questo documento) poiché il problema è stato risolto.

Dalle note di rilascio 1.2:

Problemi risolti: - visibleRegion riporta ora regione dimensionati correttamente sui dispositivi Retina

Scarica here.

-3

Forse si danno la Sede del gestore la precisione sbagliato ..

cercare di aumentare esso:

locationMgr.desiredAccuracy = kCLLocationAccuracyBest; 

La batteria sta prosciugando moreyy

+0

Non ci credo. L'SDK lo gestisce. – andybons

11

Per ottenere la delimitazione latitudine e longitudine si deve effettuare le seguenti operazioni:

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; 

Migliore rispetto s Robert

+0

Ho paura di ottenere gli stessi risultati. – andybons

1

Assomiglia alle coordinate di latitudine e longitudine che si stanno stampando e il tracciamento manuale è forse un po 'fuori misura/troncato. % f consente di stampare solo fino a 6 cifre decimali.

Ecco una questione connessa che potrebbe aiutare:

How to print a double with full precision on iOS?

+0

No. Anche con maggiore precisione usando NSNumber per la seguente proiezione: http://imgur.com/sQBUjSi Ricevo questo risultato: http://imgur.com/ZW5oB1I – andybons

+0

Aggiornato la domanda per riflettere il tuo suggerimento di precisione. Grazie. – andybons

6

Ho visto il tuo problema here. Spero che risolvano questo problema nel prossimo aggiornamento.

Ma ora siamo in grado di prendere la vera regione del visibile come questo:

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]; 

Disegno metodo poligonale:

- (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]; 
} 

Funziona anche per la mappa con il cuscinetto e l'angolo non predefinita.

+0

Questo codice era effettivo nella versione 1.3 sdk. Risposte per la nuova versione: https://developers.google.com/maps/documentation/ios/reference/index – kaspartus

Problemi correlati