Calling API for GoogleMap objective c - ios

Can anyone guide me how we can use place auto complete in GoogleMap after all the steps completed for installing pod for GoogleMaps into the project?? I have no idea about this please somebody help me!!!

I hope u have integrated google pods successfully
Import google map class
#import GoogleMaps;
Add delegate
<GMSAutocompleteViewControllerDelegate>
I have button in my screen to go for autocomplete screen.
On button IBAction write this code
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
and implement GMSAutocompleteViewControllerDelegate
- (void)viewController:(GMSAutocompleteViewController *)viewControllerdidAutocompleteWithPlace:(GMSPlace *)place {
[self dismissViewControllerAnimated:YES completion:nil];
// Do something with the selected place.
NSLog(#"Place name %#", place.name);
NSLog(#"Place address %#", place.formattedAddress);
NSLog(#"Place attributions %#", place.attributions.string);
}
- (void)viewController:(GMSAutocompleteViewController *)viewControllerdidFailAutocompleteWithError:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
// TODO: handle the error.
NSLog(#"Error: %#", [error description]);
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController*)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController*)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

Related

How to show search address on google map.?

I am working on goole map and i add the following for search bar on google map and get the coordinates of particular search address. Now i want to show it on map also after selection on place. Please look at my code.
-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
// Do something with the selected place.
NSLog(#"Place name %#", place.name);
NSLog(#"Place address %#", place.formattedAddress);
NSLog(#"Place attributions %#", place.attributions.string);
NSLog(#"lat and log%f", place.coordinate.latitude);
NSLog(#"lang %f", place.coordinate.longitude);
CLLocationCoordinate2D *coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude, place.coordinate.longitude);
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coordinates zoom:10];
[_mapView animateWithCameraUpdate:updatedCamera];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {
// TODO: handle the error.
NSLog(#"error: %ld", (long)[error code]);
[self dismissViewControllerAnimated:YES completion:nil];
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
NSLog(#"Autocomplete was cancelled.");
[self dismissViewControllerAnimated:YES completion:nil];
}
How will i update lat and long on map?
CLLocationCoordinate2D *coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude,place.coordinate.longitude);
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coordinates zoom:10];
[yourmapViewName animateWithCameraUpdate:cameraUpdate];
Update Answer
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
// Do something with the selected place.
NSLog(#"Place name %#", place.name);
NSLog(#"Place address %#", place.formattedAddress);
NSLog(#"Place attributions %#", place.attributions.string);
NSLog(#"lat and log%f", place.coordinate.latitude);
NSLog(#"lang %f", place.coordinate.longitude);
CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude,place.coordinate.longitude);
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coordinates zoom:10];
[yourmapViewName animateWithCameraUpdate:cameraUpdate];
[self dismissViewControllerAnimated:YES completion:nil];
}

change dismissVC to presentVC

I am using following method two times for login and sign up. So some times I am getting crash. Here is my code:
- (void)signIn:(NSDictionary *)params {
[[PCUtilities sharedUtilities] showActivityControllerWithMessage:nil inController:self];
[[PCWebServiceManager sharedWebServiceManager] signInWithParameters:params completionHandler:^(id responseObject, NSError *error) {
self.signInBtn.enabled = YES;
// [[PCUtilities sharedUtilities] hideActivityIndicator];
if (error) {
[self forceLogout];
[PCUtilities showAlertWithTitle:nil message:error.localizedDescription cancelButtonTitle:#"OK"];
[[PCUtilities sharedUtilities] hideActivityIndicator];
}else {
PCLoginObject *loginObject = (PCLoginObject *)responseObject;
[self dismissViewControllerAnimated:NO completion:^{
[self performSelector:#selector(handleSignInResponse:) withObject:loginObject afterDelay:0.2];
}];
}
}];
}
In above code I am using this method as two time in two different classes, so if possible can any one help me to change the below line from dismissviewcontroller to presentViewcontroller
[self dismissViewControllerAnimated:NO
completion:^{
[self performSelector:#selector(handleSignInResponse:)
withObject:loginObject
afterDelay:0.2];
}];
I am using above method two times. So according to crash report I need to change any one method to present view controller. I have tried but no success.
Try adding this method ,this helped me in my case,when I got this warning
//pragma mark - Google SignIn Delegate
- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {
}
// Present a view that prompts the user to sign in with Google
- (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController
{
[self presentViewController:viewController animated:YES completion:nil];
}
// Dismiss the "Sign in with Google" view
- (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
//completed sign In
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
//user signed in
//get user data in "user" (GIDGoogleUser object)
}
Try to set
[GIDSignIn sharedInstance].delegate = self;
in your viewDidAppear method,not in viewDidLoad

MFMessageComposeViewController not returning to application after send message ios9

Previously on iOS7, I have tested my SMS module and it worked nicely. After updating the iOS version, I noticed that the SMS module have some problems.
In my .h file
#import <MessageUI/MFMessageComposeViewController.h>
#interface ViewController : UIViewController<UITextFieldDelegate,MFMessageComposeViewControllerDelegate>
In my .m file
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled){
NSLog(#"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(#"Message sent");
}
else{
NSLog(#"Message failed");
}
}
After I press send, in the log have show "Message sent" but the view is still at the message screen. I have no idea why it will not go back to my application.
Need help to find the problem to why it will not go back to my application.
Thanks in advance.
It seems you are not dismissing the mailcomposer after it is presented. You will have to dismiss the presented MFMessageComposeViewController in the following method:
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MessageComposeResultCancelled){
NSLog(#"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(#"Message sent");
}
else{
NSLog(#"Message failed");
}
[self dismissViewControllerAnimated:YES completion:nil]; //<---- This line
}
Moreover, - (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated is deprecated since iOS 6. Use - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion instead like this:
[self presentViewController:mailComposer animated:YES completion:nil];

SKStoreProductViewControllerDelegate method not being called

I'm simply trying to implement the iTunes store screen in my application, and it displays correctly. However, when the user is finished with the screen (makes a purchase or clicks 'cancel') all I get is a white screen, and I have to completely close my app and reopen it.
It turns out my productViewControllerDidFinish method isn't being called.
I have a table view controller that has the SKStoreProductViewControllerDelegate and I'm presenting and dismissing the store view in the same class, so why isn't the delegate method being called?
- (void)toStore:(Button*)sender {
SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init];
[storeProductViewController loadProductWithParameters:#{SKStoreProductParameterITunesItemIdentifier : #"stuff"} completionBlock:^(BOOL result, NSError *error) {
if (error) {
NSLog(#"Error %# with User Info %#.", error, [error userInfo]);
} else {
[self presentViewController:storeProductViewController animated:YES completion:nil];
}
}];
}
- (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
Both in a UITableViewController. Thanks in advance!
Set delegate of SKStoreProductViewController controller.. You missed to do that..
Set it just below object allocation..
storeProductViewController.delegate = self;

Authenticate player ios app

I am trying to integrate game center into my app, however I keep getting errors. I input the following code into app delegate.m and this is what i get:
- (void)authenticateLocalPlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
}
else{
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterManager = YES;
// Get the default leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(#"%#", [error localizedDescription]);
}
else{
leaderboardIdentifier = leaderboardIdentifier;
}
}];
}
else{
_gameCenterManager = NO;
}
}
};
}
I use this code, but I get an error for this part of the code:
[self presentViewController:viewController animated:YES completion:nil];
Xcode tells me that this instance method is not found. From my understanding this is an instance method from UIView? Is there anyway I could somehow use this method in the app delegate class?
In Addition to #Raptor's answer try following.
[self.window.rootViewController presentViewController:viewController animated:YES completion:nil];
You should not use [self presentViewController:viewController animated:YES completion:nil]; to present a view controller in App Delegate, as App Delegate does not respond to presentViewController:animated:
You can use:
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

Resources