我想在iOS中使用语音导航打开Goog​​le地图应用程序

时间:2014-03-21 18:38:34

标签: ios google-maps maps

我想通过语音导航打开默认谷歌地图应用程序。 我使用以下代码打开包含源位置和目标位置的Google地图应用。谷歌地图应用程序打开正常,转弯方向也正常,但语音导航无法正常工作。 请帮帮我。

NSString* url = [NSString stringWithFormat: @"googlemaps://maps.google.com/maps?output=embed&saddr=%f,%f&daddr=%f,%f",[@"30.886537" doubleValue], [@"75.838870" doubleValue],[@"30.711423" doubleValue],[@"76.690839" doubleValue]];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString:url]];

1 个答案:

答案 0 :(得分:0)

请尝试使用以下功能:

location = "(self.street!) (self.zip!) (self.city!) (self.country!)"
func showLocationPoints(location:String)
{

    let geocoder:CLGeocoder = CLGeocoder()
    geocoder.geocodeAddressString(location, completionHandler: {(placemarks, error) -> Void in

        if((error) != nil){
            print("Error", error)
        }
        else if let placemark = placemarks!.first
        {
            let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
            let pointAnnotation:MKPointAnnotation = MKPointAnnotation()
            pointAnnotation.coordinate = coordinates
            pointAnnotation.title = "Apple HQ"

            let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01 , 0.01)
            let region:MKCoordinateRegion = MKCoordinateRegionMake(coordinates, span)
            self.mapView?.setRegion(region, animated: true)

            self.mapView?.addAnnotation(pointAnnotation)
            self.mapView?.centerCoordinate = coordinates
            self.mapView?.selectAnnotation(pointAnnotation, animated: true)
            print("Added annotation to map view")

            let place = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
            let mapItem = MKMapItem (placemark: place)

            mapItem.name = location

            let options = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsShowsTrafficKey: true]
            MKMapItem.openMapsWithItems([mapItem], launchOptions: options as? [String : AnyObject])

        }
    })
}