Come faccio ad aprire Google Maps per le direzioni utilizzando le coordinate su iPhone

voti
18

Sto usando UIMapView per visualizzare posizioni su iPhone. Voglio fare un indicazioni dalla posizione attuale alla posizione di interesse, non credo che la sua possibile utilizzare MapKit (ma se è si prega di informare) Quindi io aprirò sia l'applicazione Google Maps o Safari per visualizzarlo.

Posso farlo specificando coordinate da (posizione corrente) a coordinate (la posizione di interesse) che ho queste longitudini e latitudini. O devo usare indirizzi stradali?

Se devo usare indirizzi stradali, posso ottenere da loro la latitudine e la longitudine.

È pubblicato 10/10/2009 alle 14:58
fonte dall'utente
In altre lingue...                            


7 risposte

voti
75

Sì, non è possibile utilizzare MapKit. Si potrebbe provare a formare una richiesta URL mappe di Google che contiene sia la posizione corrente e la destinazione che si aprirà nella app mappe di Google con le istruzioni.

Ecco un esempio url:

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

Ecco come si potrebbe implementare questo nel codice:

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]];
Risposto il 12/10/2009 a 06:37
fonte dall'utente

voti
4

Usa il codice muggito per entrambe le mappe Google e Apple a 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)!)
        }
Risposto il 04/01/2017 a 19:42
fonte dall'utente

voti
2

E 'possible.Use MKMapView Prendi coordinare la posizione in cui si è toccato al telefono e con le due coordinate richiedono il KML file dal servizio web di Google, analizzare il file KML del file (campione app KML spettatore in sito degli sviluppatori) e di visualizzare i percorsi .. ..
Grazie

Risposto il 29/06/2011 a 07:23
fonte dall'utente

voti
1

Prima mappa di controllo di Google è installata nel dispositivo o no

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://");
    }

Aggiungere schema di query in .plist

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>comgooglemaps</string>
</array>
Risposto il 15/06/2017 a 11:06
fonte dall'utente

voti
1

E 'possibile mostrare rotta in MapKit: Basta usare MKPolyline

Ottengo stringa poligonale da googleMapsApi. Ho analizzarlo sul server con PHP e tornare stringa polilyne finale per la mia 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];

E che mostra:

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

Provaci.

Risposto il 28/09/2012 a 07:53
fonte dall'utente

voti
1

Una soluzione solida è quella di creare un controller di vista con un pennino che include un UIWebView, e quindi passare l'URL che esercita servizi mappa / direzione di Google. In questo modo, a mantenere l'utente nell'applicazione. Questo approccio non è sufficiente quando si tira una pagina web, perché il kit Apple non supporta lo zoom. Ma con OS4, almeno l'utente può fare doppio clic sul tasto Home e tornare alla app.

Risposto il 07/05/2010 a 00:55
fonte dall'utente

voti
-1

È possibile inviare il perno sceso a te stesso e quando si apre il link in email, mostrerà le coordinate.

Risposto il 18/08/2011 a 06:54
fonte dall'utente

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