Create custom CLPlacemark for RideIntent - ios

I'm trying to create a custom CLPlacemark using the Intents framework.
I'm importing 'Intents' at files beginning.
I found this solution:
let waypointLocation = CLLocation(latitude: 50.00, longitude: 8.00)
let waypointName = "Some Name"
let w1 = CLPlacemark.init(location: waypointLocation,
name: waypointName,
postalAddress: nil)
Unfortunately the above code gives me the following error message:
Ambiguous reference to member 'init(placemark:)'
Any ideas what's wrong?
Documentation:
init(location:name:postalAddress:) https://developer.apple.com/reference/corelocation/clplacemark/2132103-init

Just found out that in iOS 12 / Xcode 10 you also have to include the Contacts framework, as the postaladdress param has the class CNPostalAddress required for this initializer
import Intents
import Contacts

By subclassing CLPlacemark it is possible to use the Intents frameworks protocol init(location:name:postalAddress).
Somewhere in your project:
class MyPlacemark: CLPlacemark {}
Your code to create a custom CLPlacemark:
let placeLocation = CLLocation(latitude: 50.00, longitude: 8.00)
let placeName = "Some name"
let customPlacemark = MyPlacemark(location: w1Location, name: w1Name, postalAddress: nil)

You need to use
init(location:name:postalAddress);
The placemarkWithLocation call is objective-C not swift hence why it is throwing that error message.
In the documentation you will see a language selection on the right hand side. init(location:name:postalAddress is the swift call you will need to create a new place mark.

Related

iOS MapKit Get Places information and Reviews

I'm using mapkit and able to get Address for a particular location
let firstPlacemark = placemarks,
let addressDictionary = firstPlacemark.addressDictionary else { return }
// let street = addressDictionary["Street"]
// let city = addressDictionary["City"]
// let state = addressDictionary["State"]
// let zip = addressDictionary["ZIP"]
print(addressDictionary.description)
if let array = addressDictionary["FormattedAddressLines"] as? [Any] {
let address = array.map { "\($0)" }.joined(separator: ",\n")
print("Address : \(address)")
}
But Can we get more information like reviews contact no. images etc. Like Apple Maps shows (Observe Screeenshot)
Is there any API available in iOS for this or it will be provided via TripAdvisor???
P.S: I don't want to Any Google API.
Dear down voters if don't know the answers then kindly don't waste my points. It's easy to downvote, but you never know how much efforts has been added to earn those points.
OR Kindly provide me solution or show me if question is duplicate.
You can use Tripadvisor API
https://developer-tripadvisor.com/content-api/documentation/
ex.
http://api.tripadvisor.com/api/partner/2.0/location/155507?key=YOURKEY

Uber Carthage swift ridesClient.requestRide gives ride=nil

I am trying to integrate Uber SDK with my current iOS app.
I have Xcode :- 8.1 iOS :-10.1 and swift version :- 3.0
I have done setup for "Carthage" for Uber integration.
i am calling requestRide method and its always giving ride=nil
let parameterBuilder = RideParametersBuilder()
parameterBuilder.setProductID("a1111c8c-c720-46c3-8534-2fcdd730040d")
let pickupLocation = CLLocation(latitude: 37.770, longitude: -122.466)
parameterBuilder.setPickupLocation(pickupLocation, nickname: "California Academy of Sciences")
let dropoffLocation = CLLocation(latitude: 37.791, longitude: -122.405)
parameterBuilder.setDropoffLocation(dropoffLocation, nickname: "Pier 39")
let ridesClient = RidesClient()
ridesClient.requestRide(parameterBuilder.build(), completion: { ride, response in
}
Please help me.
i stuck here not able to execute my project. any suggestion will be useful for me.
Thanks in advance.

How can I use myLocation with Swift using Google Map SDK for iOS?

I am making a single view application in Xcode, with Google Map SDK. I have followed instructions online and my application can successfully load the google map view. I have also enabled myLocation, so that myLocation button shows on the map view.
I understand that clicking the myLocation button will change the camera location automatically, but I'm wondering what I should do to use the data of myLocation (say to add a marker or add a path node)?
I've tried directly accessing mapView.myLocation, for example
let lat = mapView.myLocation?.coordinate.latitude
let long = mapView.myLocation?.coordinate.longitude
path.addCoordinate(CLLocationCoordinate2D(latitude: lat!, longitude: long!))
However, this will crash the applicaton and throw:
fatal error: unexpectedly found nil while unwrapping an Optional value
What does this error message mean and how should I resolve this?
The error says that myLocation property of mapView is nil. You should check if there is a value before accessing it.
if let myLocation = mapView.myLocation {
let lat = myLocation.coordinate.latitude
let long = myLocation.coordinate.longitude
path.addCoordinate(CLLocationCoordinate2D(latitude: lat, longitude: long))
}
Also verify why myLocation is nil. It might be that the user didn't allow location services.
This will not give any errors:
let lat = mapView.myLocation?.coordinate.latitude ?? give any value of latitude
let long = mapView.myLocation?.coordinate.longitude ?? give any value of longitude

Using Bing Translator Api in Xcode using swift

I am using FGTranslator(https://github.com/gpolak/FGTranslator) to access bing translator api with swift
but the problem is that FGTranslator is written in objective c and I am using swift but according to Apple we can do it. I successfully added these classes in my project with bridging header and I also installed AFNetworking with Pod Setup. Now I can successfully compile my program without an error.
override func viewDidLoad() {
super.viewDidLoad()
let BING_CLIENT_ID = "some ID"
let BING_CLIENT_SECRET = "some Secret";
let inputText = "Bonjour"
var fr = "fr"
var to = "en"
var translator :FGTranslator = FGTranslator(bingAzureClientId: BING_CLIENT_ID, secret: BING_CLIENT_SECRET)
translator.translateText(inputText, completion:nil)
}
At the last line where translator.translateText is called completion is required which I am giving nil. Can anybody help me to get translation done. I am a newbie programmer

Swift: Extracting / downcasting CFType based CoreText types in a CFArray

I am trying to port elements of the CoreAnimationText sample to Swift. I cannot figure out though, how to extract or downcast the elements of CTRun from an array, in order to pass them to functions that expect and act upon the Swift-ified CTRun type. I either get runtime errors or linking errors from the playground snippet below
import CoreText
import QuartzCore
let text = NSAttributedString(string: "hello")
var line: CTLine = CTLineCreateWithAttributedString(text)
var ctRuns:CFArray = CTLineGetGlyphRuns(line)
let nsRuns:Array<AnyObject> = ctRuns as NSArray
nsRuns.count // == 1
// Playground execution failed: error: error: Couldn't lookup symbols:_OBJC_CLASS_$_CTRun
let nsRun = nsRuns[0] as CTRun
nsRun.self
println(nsRun.self)
let anyRuns = nsRuns as AnyObject[]
// can't unwrap Optional null
let anyRun = anyRuns[0] as CTRun
anyRun.self
println(anyRun.self)
let cft:AnyObject = anyRuns[0]
// CTRun is not contstructable with AnyObject
let runGlyphCount = CTRunGetGlyphCount(CTRun(cft));
// Can't unwrap Optional.None
let concreteRuns = anyRuns as CTRun[]
let concreteRun = concreteRuns[0] as CTRun
concreteRun.self
println(concreteRun.self)
Any ideas - am I missing something obvious? From the WWDC sessions and interop guide, I am led to believe that "Swift just takes care of this".
According to dev forums, this functionality is implemented in 6.1.
All your sample lines compile without errors and work as expected in
the latest Xcode, 6.1 (6A1052c) .
Interoperability with CF objects is impoving. You may find another
issues, in such case it'd be reported as bug.

Resources