Geocoding and ReverseGeocoding in iOS using Google Maps - ios

I want to add Google Maps in a UIView that I added in MainStoryboard (Because I want to control maps place and size).
The map shows correctly but does not listen to the events. I have added <GMSMapViewDelegate> protocol in ViewController.h and also the methods in ViewController.m and when i set the UIViewController view as the map view (Googles example self.view = GMSMapView) everything works fine.
Thanks in Advance!

You have to set your ViewController as a GMSMapView delegate.
in viewDidLoad:
mapView.delegate = self;

Related

Change UIViewcontroller with if statement

I'm have two view controllers that are same the only difference is first show a mapview and other isn't show a mapview.
In this case, i have segmented control where in segment 0 is displaying the View Controller with the mapView but I have some other data that doesn't have information to be displayed in the mapview. I would like to know how I could do this (with an if statement or something similar) since the other UIView does not have segue.
This is essentially a bad practice. If your app needs 2 or more screens with similar design, then you should be using one viewcontroller/scene only. This way, if a design change happens, you only need to change once.
2 viewcontrollers with difference of only a map visibility isn't hard to code. You just declare a property bool for that viewcontrollerA like so:
#property (nonatomic, assign) BOOL isMapVisible;
Then on viewDidload on viewControllerA, you set the visibility of this map by:
if (!_isMapVisible) {
[_mapView setHidden = YES];
}
The caller viewcontroller then implements prepareForSegue and set the _isMapVisible accordingly prior to executing the segue to viewControllerA.
You can set mapview height to 0 if you want to hide it. Like:
mapView.frame.size.height = 0

Where to initialize subview?

I am new to iOS development and I am currently reading the book : iOS Programming (Objective C) by Big Nerd Ranch.
I am confused as in where to initialize subviews such as UIButtons, UIImageView while creating views programtically:
Should the intialization be done in the Main UIView i.e in the
initWithFrame method and maintain a additional weak reference to the subview in the UIView.
or
should I do it in the UIViewControllers loadView method and maintain a weak reference to the subview in the uiviewcontroller (Same approach used while creating UIVew using the interface builder).
I have seen both the approaches being used in various stackoverflow posts but no post that explains which approach is the right one.
you can initialize as per your app's requirement. If any view or button or anything is part of initial setup of your app then you should initialize it in viewDidload.
Now, for example there is requirement like user press button and then new view will be created then you can initialize view in button's click method etc.
So, it's depends on your requirement.
Static views which will live from start to and of app should be initialize in viewdidload, because this is the first method getting called of viewcontroller.
hope this will help :)
It dependes on which architecture you are using. Apple raises the flag of Model-View-Controller, but in fact, UIViewControllers are the View.
For Example:
Let's say that you have a pretty LoginViewController. When you instantiate it, you will be doing something like
LoginViewController *loginVC = [[LoginViewController alloc] init];
At this point, no view is loaded. Your ViewController has just executed the init method, nothing else. When the system calls
loginVC.view
the first method to be executed will be
- (void)loadView;
there you should do exactly that, load your view. So, the approach i like is to have an additional LoginView.
- (void)loadView
{
// you should have a property #property (nonatomic, strong) LoginView *loginView;
self.loginView = [[LoginView alloc] init];
self.view = self.loginView;
}
and in the LoginView init method, you should put your code to build up the view.
However, you could eliminate LoginView, and instantiate all your subviews like this:
- (void)loadView
{
self.view = [[UIView alloc] init];
UIButton *button = [[UIButton alloc] initWithTargetBlaBlaBla...];
[self.view addSubview:button];
// add more fancy subviews
}
In my experience, the first approach is much cleaner than the second one. It also makes version control a lot easier (try to merge a xib, I dare you). I always use MyView.m to build the view (a.k.a setup constriants, style) and use MyViewController.m things like animations, lifeCycle. I like to think that MyView.m is the programatic xib, so anything that you can do with xibs, you should me able to do it inside your view.
Hope it helps!!

Select a marker method with Google Maps iOS SDK

I have an app that sends a notification every time the user approaches to a map on GMSMapView.
I want that when the user opens the notification (UILocalNotification) the marker will be already selected and its info window will be visible.
I've searched for a method in the delegate that do that (selectAMarker:/selectAMarkerInPosition: or something like that) but I haven't found something like that.
Anyone knows a method that do that/know how can I do that?
Is it even possible?
Thank you very much!
I think you like this method
-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
NSLog(#"try");
return YES;
}
Dont Forget to call delegate
#interface ViewController : UIViewController <GMSMapViewDelegate>
and
yourmapView_.delegate = self;

Add webMap as layer with ArcGIS mapView for iOS app project

I'm trying to code in a basic ArcGIS workflow into my iOS project. I am new to this platform and can use some pointers. My workflow is as follows.
1.) Create mapView displaying satellite (world style) map.
2.) Add a public webMap from my user account on ArcGIS Online as an overlay/layer on the satellite map.
What I've tried
//.h
#import <ArcGIS/ArcGIS.h>
#interface ViewController : UIViewController <AGSWebMapDelegate>
#property (strong, nonatomic) IBOutlet AGSMapView *mapView;
//.m
// Add basemap
NSURL* url = [NSURL URLWithString:#"http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"];
AGSTiledMapServiceLayer *tiledLayer = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:url];
[self.mapView addMapLayer:tiledLayer withName:#"Basemap Tiled Layer"];
//If I run this part alone, I'll get the satellite map.
AGSWebMap* webmap = [[AGSWebMap alloc] initWithItemId:#"bb9b8c172e8142f995526bf658078f54" credential:nil];
webmap.delegate = self;
[webmap openIntoMapView:self.mapView];
//When I add this webMap code and run the project, I get a blank white screen.
//.m cont.
- (void)mapViewDidLoad:(AGSMapView *) mapView {
NSLog(#"mapView didLoad");
}
- (void) webMapDidLoad:(AGSWebMap*) webMap {
NSLog(#"webmap added successfully");
}
//Neither of these logs get called.
Questions.
1.) Is it right to use AGSTiledMapServiceLayer as my basemap? Also, is it right to use AGSWebMap for my ArcGIS Online map?
2.) My goal is to be able to add and remove multiple layers to and from a satellite basemap, one at a time. Am I on the right track?
I'm currently using MapBox to achieve this but I'm starting to experiment with ArcGIS SDK and it's features.
Thanks in advance.
You are almost there. Make sure all 3 of these items are in the proper pace.
From the discussion from https://developers.arcgis.com/ios/objective-c/guide/viewing-web-map.htm.
Make these calls where you made them before (presumably viewDidLoad)
instantiate an AGSWebMap object // 1
An instance of your class must then be set as the web map's delegate // 2
// 1
AGSWebMap* webmap = [[AGSWebMap alloc] initWithItemId:#"bb9b8c172e8142f995526bf658078f54" credential:nil];
// 2
webmap.delegate = self;
Then update the handler webMapDidLoad() // 3
// open the web map into a map view in the delegate handler
- (void) webMapDidLoad:(AGSWebMap*) webMap {
// 3
[webmap openIntoMapView:self.mapView];
NSLog(#"webmap added successfully");
}

UIAccelerometer called from subview not working

I have an "interesting" issue with the UIAccelerometer in an app for the iPad.
In my UIViewController I have a method that activates the Accelerometer. This is how it looks like:
-(void)startAcc{
UIAccelerometer *gForce = [UIAccelerometer sharedAccelerometer];
gForce.delegate = self;
gForce.updateInterval = kUpdateInterval;
}
In my viewWillAppear I call this method to activate the Accelerometer, and it works just fine. I recieve accelerations and use it to move a view on screen.
On user input I then load another view (UIView) that need to use the accelerometer. So I stop the accelerometer in my UIViewController with this code:
[UIAccelerometer sharedAccelerometer].delegate = nil;
I then load the UIView and activates the accelerometer there in the same way. All works just fine.
My issue begins when I want to close the UIView and start the accelerometer in the UIViewController again. I stop it in the UIView and call the startAcc method in my UIViewController from the UIView. The method executes, but I receive no accelerations :-(
Same method, but different results.
Can anyone guide me to what I am missing here?
Thanks
Solved it. By putting [self resignFirstResponder]; after I call the startAcc method from the subview it works.

Resources