Hoe open ik Google Maps voor een routebeschrijving met behulp van coördinaten op de iphone

stemmen
18

Ik gebruik UIMapView naar locaties op de iPhone weer te geven. Ik wil een aanwijzingen van de huidige locatie te doen naar de locatie van belang, denk ik niet dat het mogelijk met behulp van MapKit (maar als het is gelieve te informeren) Dus ik zal ofwel de Google Maps-applicatie of safari naar het weer te geven te openen.

Kan ik dit doen door het specificeren van coördinaten van (huidige locatie) naar coördineert (de locatie van belang) Ik heb deze lengte- en breedtegraden. Of moet ik adressen gebruiken?

Als ik moet wel adressen te gebruiken, kan ik ze uit de lengte- en breedtegraad.

De vraag is gesteld op 10/10/2009 om 14:58
bron van user
In andere talen...                            


7 antwoorden

stemmen
75

Ja, het is niet mogelijk met behulp van MapKit. Je zou kunnen proberen om een ​​Google maps url verzoek dat zowel uw huidige locatie en bestemming die wordt geopend in de Google Maps-app met de aanwijzingen bevat te vormen.

Hier is een voorbeeld url:

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

Hier is hoe je dit in de code zou kunnen implementeren:

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]];
antwoordde op 12/10/2009 om 06:37
bron van user

stemmen
4

Gebruik hieronder code voor zowel Google en Apple maps 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)!)
        }
antwoordde op 04/01/2017 om 19:42
bron van user

stemmen
2

Het is possible.Use MKMapView Klik hier voor de locatie te coördineren waar u aan de telefoon afgetapt en het gebruik van de twee coördinaten van het verzoek KML- bestand van de Google Web service, ontleden het KML -bestand (sample app KML kijker in developer site) en de routes weer te geven .. ..
Dank u

antwoordde op 29/06/2011 om 07:23
bron van user

stemmen
1

Controleer eerst google map is geïnstalleerd in het apparaat of niet

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

Creëer een query-schema in .plist

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>comgooglemaps</string>
</array>
antwoordde op 15/06/2017 om 11:06
bron van user

stemmen
1

Het is mogelijk om de route in MapKit tonen: Gebruik gewoon MKPolyline

Ik krijg polylijn reeks van googleMapsApi. Ik ontleden op de server met php, en terug te keren laatste polilyne string naar mijn 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];

En het tonen van:

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

Probeer het eens.

antwoordde op 28/09/2012 om 07:53
bron van user

stemmen
1

Een solide oplossing is om een ​​uitzicht controller met een NIB dat een UIWebView opgenomen en als vervolgens de URL dat Google's kaart / richting diensten uitoefent. Op deze manier kan de gebruiker in de applicatie te houden u. Deze aanpak is niet voldoende bij het trekken van een webpagina, omdat de Apple kit niet zoomen ondersteunen. Maar met OS4, in ieder geval kan de gebruiker dubbelklikken op de home-knop en ga terug naar de app.

antwoordde op 07/05/2010 om 00:55
bron van user

stemmen
-1

U kunt de geplaatste speld e-mail naar jezelf en wanneer je de link opent in e-mail, zal het de coördinaten te tonen.

antwoordde op 18/08/2011 om 06:54
bron van user

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