Wie eröffne ich Google Maps für Richtungen Koordinaten auf dem iPhone

stimmen
18

Ich verwende UIMapView Stellen auf dem iPhone angezeigt werden soll. Ich möchte eine Richtung von der aktuellen Position zu dem Ort von Interesse zu tun, ich glaube nicht, seine mögliche Verwendung MapKit (aber wenn es bitte informieren) Also ich öffnet entweder die Google Maps-Anwendung oder Safari um es anzuzeigen.

Kann ich (der Ort von Interesse) Ich habe diese Längen- und Breitengrade Koordinaten tun diese Koordinaten aus (aktuelle Position) durch Angabe. Oder muss ich die Straße Adressen verwenden?

Wenn ich die Straße Adressen müssen verwenden, kann ich bekommen sie von der Breite und Länge.

Veröffentlicht am 10/10/2009 um 14:58
quelle vom benutzer
In anderen Sprachen...                            


7 antworten

stimmen
75

Ja, es ist nicht möglich, mit MapKit. Sie könnten versuchen, eine Google-Maps-URL Anfrage zu bilden, die sowohl Ihre aktuelle Position und das Ziel enthält, die in dem Google Maps App mit den Richtungen öffnen.

Hier ist ein Beispiel-URL:

http://maps.google.com/?saddr=34.052222,-118.243611&daddr=37.322778,-122.031944

Hier ist, wie Sie diese in Ihrem Code implementieren könnte:

CLLocationCoordinate2D start = { 34.052222, -118.243611 };
CLLocationCoordinate2D destination = { 37.322778, -122.031944 };    

NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
                                 start.latitude, start.longitude, destination.latitude, destination.longitude];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
Beantwortet am 12/10/2009 um 06:37
quelle vom benutzer

stimmen
4

Verwenden Sie unten Code für beide Google und Apple Karten in Swift 3 -

if UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!)
        {
            let urlString = "http://maps.google.com/?daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&directionsmode=driving"

            // use bellow line for specific source location

            //let urlString = "http://maps.google.com/?saddr=\(sourceLocation.latitude),\(sourceLocation.longitude)&daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&directionsmode=driving"

            UIApplication.shared.openURL(URL(string: urlString)!)
        }
        else
        {
            //let urlString = "http://maps.apple.com/maps?saddr=\(sourceLocation.latitude),\(sourceLocation.longitude)&daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&dirflg=d"
            let urlString = "http://maps.apple.com/maps?daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&dirflg=d"

            UIApplication.shared.openURL(URL(string: urlString)!)
        }
Beantwortet am 04/01/2017 um 19:42
quelle vom benutzer

stimmen
2

Es ist possible.Use MKMapView die Lage koordinieren, wo Sie am Telefon angezapft und mit den beiden Koordinaten die Anfrage KML - Datei aus dem Google - Web - Service, die analysieren KML - Datei (Beispielanwendung KML - Viewer in Entwickler - Website) und die Routen angezeigt werden .. ..
Danke

Beantwortet am 29/06/2011 um 07:23
quelle vom benutzer

stimmen
1

Prüfen Sie zuerst, google map wird in Gerät installiert ist oder nicht

if ([[UIApplication sharedApplication] canOpenURL:
         [NSURL URLWithString:@"comgooglemaps://"]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"comgooglemaps://?saddr=23.0321,72.5252&daddr=22.9783,72.6002&zoom=14&views=traffic"]];
    } else {
        NSLog(@"Can't use comgooglemaps://");
    }

In Abfrageschema in .plist

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>comgooglemaps</string>
</array>
Beantwortet am 15/06/2017 um 11:06
quelle vom benutzer

stimmen
1

Es ist möglich, Route in MapKit zu zeigen: Verwenden Sie einfach MKPolyline

Ich bekomme Linienzug String aus googleMapsApi. Ich parse es auf dem Server mit PHP und Rückkehr letzten polilyne Zeichenfolge meine App.

NSMutableArray *points = [myApp decodePolyline:[route objectForKey:@"polyline"]];

if([points count] == 0)
{
    return;
}

// while we create the route points, we will also be calculating the bounding box of our route
// so we can easily zoom in on it. 
MKMapPoint northEastPoint; 
MKMapPoint southWestPoint; 

// create a c array of points. 
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * [points count]);

for(int idx = 0; idx < points.count; idx++)
{
    // break the string down even further to latitude and longitude fields. 
    NSString* currentPointString = [points objectAtIndex:idx];
    NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];

    CLLocationDegrees latitude  = [[latLonArr objectAtIndex:0] doubleValue];
    CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];

    // create our coordinate and add it to the correct spot in the array 
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);

    MKMapPoint point = MKMapPointForCoordinate(coordinate);

    if (idx == 0) {
        northEastPoint = point;
        southWestPoint = point;
    }
    else 
    {
        if (point.x > northEastPoint.x) 
            northEastPoint.x = point.x;
        if(point.y > northEastPoint.y)
            northEastPoint.y = point.y;
        if (point.x < southWestPoint.x) 
            southWestPoint.x = point.x;
        if (point.y < southWestPoint.y) 
            southWestPoint.y = point.y;
    }
    pointArr[idx] = point;
    _currentLenght++;
}

// create the polyline based on the array of points. 
self.routeLine = [MKPolyline polylineWithPoints:pointArr count:points.count];

_routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, 
                           northEastPoint.x - southWestPoint.x, 
                           northEastPoint.y - southWestPoint.y);

// clear the memory allocated earlier for the points
free(pointArr);

if (nil != self.routeLine) {
        [self.mapView addOverlay:self.routeLine];
}
[self.mapView setVisibleMapRect:_routeRect];

Und zeigt:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;

if(overlay == self.routeLine)
{
    self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
    self.routeLineView.fillColor = [UIColor blueColor];
    self.routeLineView.strokeColor = TICNavigatorColor;
    self.routeLineView.lineWidth = 7;
    self.routeLineView.lineJoin = kCGLineJoinRound;
    self.routeLineView.lineCap = kCGLineCapRound;

    overlayView = self.routeLineView;
}

return overlayView; 
}

Versuche es.

Beantwortet am 28/09/2012 um 07:53
quelle vom benutzer

stimmen
1

Eine feste Lösung ist eine View-Controller mit einem NIB zu erstellen, die eine UIWebView enthält, und dann die URL übergeben, die die Google-Karte / Richtungs Dienste ausübt. Auf diese Weise halten Sie den Benutzer in der Anwendung. Dieser Ansatz ist nicht ausreichend, wenn eine Web-Seite nach oben ziehen, da der Apple-Kit nicht Zoomen unterstützt. Aber mit OS4, zumindest kann der Benutzer doppelt auf den Button klicken Hauses und zurück zum App wechseln.

Beantwortet am 07/05/2010 um 00:55
quelle vom benutzer

stimmen
-1

Sie können die abgelegte Stift, um sich eine E-Mail und wenn Sie auf den Link in E-Mail öffnen, werden die Koordinaten zeigen.

Beantwortet am 18/08/2011 um 06:54
quelle vom benutzer

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more