Google Maps iOS SDK mylocation button not showing - google-maps-sdk-ios

I enabled myLocation and myLocationButton,
but it not showing on my view.
And I try log _mapView.myLocation it's nil.
I need to showing myLocation dot and myLocationButton.
Have some one can help me, thanks!
//
// ViewController.m
//
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <GoogleMaps/GoogleMaps.h>
#import "Reachability.h"
#interface ViewController ()<GMSMapViewDelegate,CLLocationManagerDelegate>
{
CLLocationManager * locationManager;
CLLocation *currentLocations;
Reachability * udnReach;
};
#property (strong,nonatomic) GMSMapView * mapView;
#property (strong,nonatomic) NSDictionary * dic;
#property (nonatomic,strong) NSTimer * updatetimer;
#end
#implementation ViewController {
}
- (void)viewDidLoad {
locationManager =[[CLLocationManager alloc]init];
locationManager.delegate =self;
if ([locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.activityType = CLActivityTypeAutomotiveNavigation;
[locationManager startUpdatingLocation];
_mapView.delegate = self;
_mapView.myLocationEnabled = YES;
_mapView.settings.myLocationButton = YES;
//Map
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
longitude:locationManager.location.coordinate.longitude
zoom:16];
_mapView= [GMSMapView mapWithFrame:CGRectZero camera:camera];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(networkStatusChanged:) name:kReachabilityChangedNotification object:nil];
udnReach=[Reachability reachabilityWithHostName:#"google.com"];
// udnReach = [Reachability reachabilityForInternetConnection];
[udnReach startNotifier];
[self updatebike];
self.view = self.mapView;
NSLog(#"User's location: %#", _mapView.myLocation);
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
}

i find to show button and get userlocation
// Rather than setting -myLocationEnabled to YES directly,
// call this method:
- (void)enableMyLocation
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusNotDetermined)
[self requestLocationAuthorization];
else if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted)
return; // we weren't allowed to show the user's location so don't enable
else
[self.view setMyLocationEnabled:YES];
}
// Ask the CLLocationManager for location authorization,
// and be sure to retain the manager somewhere on the class
- (void)requestLocationAuthorization
{
_locationAuthorizationManager = [[CLLocationManager alloc] init];
_locationAuthorizationManager.delegate = self;
[_locationAuthorizationManager requestAlwaysAuthorization];
}
// Handle the authorization callback. This is usually
// called on a background thread so go back to main.
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status != kCLAuthorizationStatusNotDetermined) {
[self performSelectorOnMainThread:#selector(enableMyLocation) withObject:nil waitUntilDone:[NSThread isMainThread]];
_locationAuthorizationManager.delegate = nil;
_locationAuthorizationManager = nil;
}
}

Related

ViewController with Skview - SpriteKit SKScene

first try and bit stuck on this one...
I Have a ViewController that I wish to display an SKScene in its view
I've tried everything I can think of but its not showing
add SpriteKit/SpriteKit.h
Main.storyboard has a single view controller (myViewController).
myViewController's view - change class to be SKView. (see pic below)
Viewdidload
link to SKScene I wish to load (HelloScene) #import "HelloScene.h"
//ViewController.m
#import "myViewController.h"
#import <SpriteKit/SpriteKit.h>
#import "HelloScene.h"
#interface myViewController ()
#end
#implementation myViewController
- (void)viewDidLoad
{
[super viewDidLoad];
SKView *spriteView = (SKView *) self.view;
spriteView.showsDrawCount = YES;
spriteView.showsNodeCount = YES;
spriteView.showsFPS = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
HelloScene.h
#import <SpriteKit/SpriteKit.h>
#interface HelloScene : SKScene
#end
HelloScene.m
#import "HelloScene.h"
#interface HelloScene ()
#property BOOL contentCreated;
#end
#implementation HelloScene
- (void)didMoveToView: (SKView *) view
{
[self LoadSceneContents];
}
- (void)LoadSceneContents
{
self.backgroundColor = [SKColor blueColor];
self.scaleMode = SKSceneScaleModeAspectFit;
[self addChild: [self newHelloNode]];
}
- (SKLabelNode *)newHelloNode
{
SKLabelNode *helloNode = [SKLabelNode labelNodeWithFontNamed:#"Chalkduster"];
helloNode.text = #"Hello, World!";
helloNode.fontSize = 42;
helloNode.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
return helloNode;
}
#end
Above:Selecting the view controller’s view object and change its class to SKView
Had missed to configure the scene properly...
// Create and configure the scene.
HelloScene *theScene = [HelloScene sceneWithSize:spriteView.bounds.size];
theScene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[spriteView presentScene:theScene
];
Hope it helps somebody else

PageViewController with Different xib (rather than different UIViewControllers)

I am new to programming and am trying to make a PageViewController using xib's.
I have followed a tutorial found on SO which showed me how to make a PageViewController using different UIViewControllers in storyboard (I have pasted the code below). This works well, however, for my final app I would like to use a PageViewController in an xib (with multiple different xibs).
#import "IntroPages.h"
#implementation IntroPages
{
NSArray *myViewControllers;
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
UIViewController *p1 = [self.storyboard instantiateViewControllerWithIdentifier:#"1ID"];
UIViewController *p2 = [self.storyboard instantiateViewControllerWithIdentifier:#"2ID"];
UIViewController *p3 = [self.storyboard instantiateViewControllerWithIdentifier:#"3ID"];
UIViewController *p4 = [self.storyboard instantiateViewControllerWithIdentifier:#"4ID"];
myViewControllers = #[p1,p2,p3,p4];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
}
-(UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
return myViewControllers[index];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
--currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
++currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(NSInteger)presentationCountForPageViewController: (UIPageViewController *)pageViewController {
return myViewControllers.count;
}
-(NSInteger)presentationIndexForPageViewController: (UIPageViewController *)pageViewController {
return 0;
}

Alert View directs to an empty view controller without buttons

I'm trying to make an alert view so that upon selecting "Yes" (one of the buttons in AlertView), the user is directed to a new view controller with a button which I made via Storyboard. My code for the IBAction is as follows:
- (IBAction)alertButton:(UIButton *)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome Back to SymTrack!" message:#"Did you have reoccuring symptoms?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
}
This is the code for the clickedButtonAtIndex which gives me the empty view controller without the button:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [[UpdateViewController alloc] init];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
I've also tried these other codes for clickedButtonAtIndex but I got NSException for all of them:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:#"UpdateViewController"];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
or
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:#"UpdateViewController"];
UINavigationController *alertNC = [[UINavigationController alloc] initWithRootViewController:updateVC];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
note: all this code is within the view controller with the button that upon clicking brings the alert view up.
Thanks in advance!

Cannot load the Google Maps view in iOS

I'm trying to load google maps view in iOS following the guide here
I created a new viewController for the map view called iptechMapViewController.h , iptechMapViewController.m and iptechMapViewController.xib
Here is the code in iptechMapViewController.m :
#import "iptechMapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#interface iptechMapViewController ()
{
GMSMapView *mapView_;
}
#end
#implementation iptechMapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Then in another view controller named iptechFlipsideViewController.m I'm trying to show the iptechMapViewController as follows:
- (IBAction)showMap:(id)sender
{
iptechMapViewController *controller = [[iptechMapViewController alloc] initWithNibName:#"iptechMapViewController" bundle:nil];
[self.view addSubview:controller.view];
}
But after clicking the showMap button which is connected to the IBAction showMap, and after iOS asks permission to access my location alert appears and I touch OK, after that nothing shows up and in the console I get the following error"
Failed to make complete framebuffer object 8cd6
Thanks
Passing CGRectZero to mapWithFrame only works if the map view is the root view controller's root view - in which case it is resized to fit the screen. In your case since the map is a subview, you will need to specify a size when creating the map view.

How to enable cc touch events when i add CCLayer to UIViewController

here is my code:
#import "VirusViewController.h"
#import "MainGame.h"
#import "cocos2d.h"
#implementation VirusViewController
#synthesize window;
- (void)loadView {
// Initialization code
CC_DIRECTOR_INIT();
CCDirector *director = [CCDirector sharedDirector];
//landscape
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[director setDisplayFPS:YES];
//turn on multi-touch
EAGLView *cocosView = [director openGLView];
[cocosView setMultipleTouchEnabled:YES];
self.view = cocosView;
//default texture formats...
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene:[MainGame scene]];
}
-(void)viewDidLoad
{
UIButton *nextButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 40, 64, 64)];
[nextButton setImage:[UIImage imageNamed:#"homeButton.png"] forState:UIControlStateNormal];
[nextButton addTarget:self action:#selector(goBack) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nextButton];
[nextButton release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[[CCDirector sharedDirector] purgeCachedData];
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[[CCDirector sharedDirector] release];
[window release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
-(void)goBack
{
[self.navigationController popViewControllerAnimated:YES];
}
nextButton is not receiving touch events when i init the CC_Director_INIT();
also - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
is not working inside a subview of MainGame.h
in other words... I can't receive any touch events
Try giving your layer these methods
- (void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
[super onEnter];
}
- (void)onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
sharedDispatcher is deprecated - you should use this instead:
[[CCDirector sharedDirector] touchDispatcher]