Unable to use PXGoogleDirections in Objective C project
billylo1 opened this issue · 1 comments
billylo1 commented
After importing <PXGoogleDirections/PXGoogleDirections-Swift.h>, I try this:
PXGoogleDirections *api = [PXGoogleDirections new];
api = [api initWithApiKey:@"myGoogleKey"];
but I couldn't find the method for generating a route... any hints?
poulpix commented
Hi @billylo1, sorry for the late reply.
Have a look at either the Readme file (https://github.com/poulpix/PXGoogleDirections/blob/master/README.md), or the sample project located in the Sample folder (https://github.com/poulpix/PXGoogleDirections/tree/master/Sample).
Here's how you would do it in Swift:
let directionsAPI = PXGoogleDirections(apiKey: "<insert your Google API key here>",
from: PXLocation.CoordinateLocation(CLLocationCoordinate2DMake(37.331690, -122.030762)),
to: PXLocation.SpecificLocation("Googleplex", "Mountain View", "United States"))
directionsAPI.calculateDirections({ response in
switch response {
case let .Error(_, error):
// Oops, something bad happened, see the error object for more information
break
case let .Success(request, routes):
// Do your work with the routes object array here
break
}
})
Here's how you would probably do it in Objective-C (untested, just translated from Swift):
PXGoogleDirections *api = [[PXGoogleDirections alloc] initWithApiKey:@"myGoogleKey"
from: [PXLocation coordinateLocation:CLLocationCoordinate2DMake(37.331690, -122.030762)]
to: [PXLocation specificLocation:@"Googolplex" city:@"Mountain View" country:@"United States")]];
[api calculateDirections: ^{
...
}];