2013-03-10 2 views
8

EDIT: Das ist jetzt ein bestätigter Fehler mit this SDKGoogle Maps iOS SDK: Wie erhalte ich exakte Breiten- und Längenkoordinaten von der visibleRegion einer Kamera?

ich verwende Version 1.1.1.2311 der Google Maps für iOS SDK, und ich suche den Begrenzungs Breiten- und Längengrad-Koordinaten für die sichtbare Karte finden auf dem Bildschirm.

Ich verwende den folgenden Code, mir zu sagen, was die aktuelle Projektion:

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

aus dem Header zu lesen, scheint es, dass es nicht, wenn die Kamera bewegt aktualisiert werden kann. genug Messe ...

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

aber scheint es, jedes Mal wenn die delegierte Methode zur Aktualisierung aufgerufen wird, so dass ich versuchte, die Koordinaten zu zeichnen, sie zu testen ...

Für die folgende auf meinem Handy:

my app's current projection

der Ausgang des NSLog von oben gibt mir folgendes:

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

Wenn diese Koordinaten mit this Plotten ich einen Vorsprung auf, der aus scheint:

actual projection

Diese Koordinaten konsistent über App Einführungen sind, die mich führt, dass ich entweder konsequent bin, zu glauben, etwas falsch zu machen, ich bin Missverständnis, was visibleRegion ist, oder ich habe einen Fehler entdeckt. Möchte mir jemand helfen, herauszufinden, welcher es ist?

+0

Stuck in der gleichen Ausgabe. Lassen Sie es mich wissen, wenn Sie irgendwelche Lösungen gefunden haben. Danke – Mangesh

Antwort

2

Die Lösung ist das Herunterladen der neuesten Version des SDK (1.2 zum Zeitpunkt der Erstellung), da das Problem behoben wurde.

Von den 1.2 Release Notes:

Gelöste Probleme: - visible jetzt berichtet richtig dimensioniert Region auf Retina-Geräten

Herunterladen here.

-3

Vielleicht geben Ihnen den Standort-Manager die falsche Genauigkeit ..

Versuch, es zu erhöhen:

locationMgr.desiredAccuracy = kCLLocationAccuracyBest; 

Die Batterie moreyy

+0

Ich glaube nicht. Das SDK handhabt das. – andybons

11

wird Ablassen des Begrenzungs Breiten- und Längen Sie erhalten müssen Führen Sie die folgenden Schritte aus:

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; 

Beste Bewertung s Robert

+0

Ich fürchte, ich bekomme die gleichen Ergebnisse. – andybons

1

Sieht so aus, als wären die Breiten- und Längenkoordinaten, die Sie ausdrucken und manuell zeichnen, möglicherweise ein bisschen/werden abgeschnitten. % f wird standardmäßig nur auf 6 Dezimalstellen gedruckt.

Hier ist eine weitere Frage, die helfen könnten:

How to print a double with full precision on iOS?

+0

Nein. Auch mit erhöhter Präzision mit NSNumber für die folgende Projektion: http://imgur.com/sQBUjSi Ich bekomme diese Ausgabe: http://imgur.com/ZW5oB1I – andybons

+0

Die Frage aktualisiert, um Ihren Präzisionsvorschlag zu reflektieren. Vielen Dank. – andybons

6

Ich sah Ihr Problem here. Ich hoffe, dass sie dieses Problem im nächsten Update beheben.

Aber jetzt können wir den realen sichtbaren Bereich wie folgt nehmen:

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

Zeichnung Linienzug Methode:

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

Es funktioniert sogar für Karte mit Nicht-Standard-Lagern und Winkeln.

+0

Dieser Code war unter 1.3 SDK Version aktuell. Refs für neue Version: https://developers.google.com/maps/documentation/ios/reference/index – kaspartus

Verwandte Themen