GMSMarker custom infoWindow doesn't shown - ios

I've implemented -mapView: markerInfoWindow: on my application and until now everything was working perfectly, but yesterday I've updated the Google Maps iOS SDK to the latest version (1.12.23211.0) and since then the info window doesn't being shown and the default info window (white bar with a title) is displayed instead.
I tried to reinstall the last version of the SDK (using Cocoa pods) but it's still not working (my custom info window isn't being shown).
Can anyone help me to solve this problem?
My code:
myVC:
-(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
//Creating "infoWindow"(infoWindow) and setting it with nib file called "infoWindow"
infoWindow *infoWindow=[[[NSBundle mainBundle] loadNibNamed:#"infoWindow" owner:self options:nil] firstObject];
//Setting "infoWindow"(infoWindow)'s storeNameLabel's text to "marker"(customMarker)'s title
infoWindow.storeNameLabel.text=((customMarker*)marker).title;
//Creating "fullAddress"(NSString) ands setting it to "marker"(customMarker)'s address
NSString *fullAddress = ((customMarker*)marker).address;
//Creating "addressArray"(NSArray) and adding it "address" without the city name (until the "," char)
NSArray *addressArray = [fullAddress componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#","]];
//Setting "infoWindow"(infoWindow)'s storeAddressLabel's text to "addressArray"(NSArray) first object
infoWindow.storeAddressLabel.text=[addressArray firstObject];
//Returning "infoWindow"(infoWindow)
return infoWindow;
}
-(void)createMarkerWithStore:(Store*)store
{
dispatch_async(dispatch_get_main_queue(), ^{
customMarker *marker=[[customMarker alloc] initWithPosition:store.geoPoint andTitle:store.storeName andAddress:store.address andIcon:store.category.markerIcon];
marker.map=self.mapView;
store.marker=marker;
});
}
customMarker:
-(void)awakeFromNib
{
self.storeNameLabel.adjustsFontSizeToFitWidth=YES;
self.storeAddressLabel.adjustsFontSizeToFitWidth=YES;
}
customMarker:
-(instancetype)initWithPosition:(CLLocationCoordinate2D)position andTitle:(NSString*)title andAddress:(NSString*)address andIcon:(UIImage*)icon
{
self=[super init];
if (self) {
self.position=position;
self.title=title;
self.address=address;
self.icon=icon;
self.flat=YES;
self.appearAnimation=kGMSMarkerAnimationPop;
}
return self;
}
Thank you very much!

The problem was that I forgot to set the delegate to the map

Related

The app gets frozen when returning a custom UIView as a marker infoWindow (Google Maps iOS SDK)

I have a custom UIView (with a xib, .h and .m files) and I want it to be my GMSMarker's info window. But when I return my custom UIView in the -mapView: markerInfoWindow: method, the app just gets frozen and stuck (it's not even crashing).
My code is:
-(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
//Creating "infoWindow"(infoWindow) and setting it with nib file called "infoWindow"
CustomMarkerInfoWindow *infoWindow=[[[NSBundle mainBundle] loadNibNamed:#"CustomMarkerInfoWindow" owner:self options:nil] lastObject];
//Returning "infoWindow"(infoWindow)
return infoWindow;
}
I have no idea why it's freezing and I know for sure that this code worked in the past, so I can't understand what's wrong.
Can someone help me with this?
Thank you!
Put this method in your custom view implementation file
-(void)didMoveToSuperview{
self.superview.autoresizesSubviews = NO;
}

iOS GMaps delegate mapView: markerInfoWindow: not implemented

I am trying to create custom Info Window for marker. I am using Google Maps SDK for iOS.
I have created custom XIB file with all objects. Created class for it.
Called GMSMapViewDelegate in Header file
in implementation file I implemented following method:
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
NSLog(#"Implementing delegate Method");
CustomInfoWindow *infoWindow = [[[NSBundle mainBundle]
loadNibNamed:#"InfoWindow"
owner:self
options:nil]
objectAtIndex:0];
infoWindow.title.text = #"This is title";
infoWindow.address.text = #"This is address";
infoWindow.status.text = #"Here will be status";
return infoWindow;
}
But there is still default marker. What could be the issue?
Thanks for help.
Try if not add GMSMapView Delegate
You add GMSMapView Delegate in in implementation file
GMSMapView * mapView_ = [GMSMapView mapWithFrame:viewmapbaseView.bounds camera:camera];
mapView_.delegate=self;

How to use custom callout for annotation when using Google maps in iOS?

I am using Google Maps in iOS app .So far I am able to show user location on the map. I am trying to use a custom callout when a annotation is clicked.
This is what I have done so far.
1] Created aXIB file and assigned a class name to it of a UIView subclass.
2] Used markerInfoWindow delegate method as below.
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
CustomGoogleCallOut *view = [[[NSBundle mainBundle]loadNibNamed:#"CustomGoogleCallOut" owner:self options:nil]objectAtIndex:0];
view.callOutImageView.image = [UIImage imageNamed:#"avatar.png"];
view.callOutTitleLabel .text = #"title";
view.callOutUserName.text = #"Mario";
return view;
}
However I am not able to see call out.What am I missing here?
You are missing delegate. in h file
: UIViewController<GMSMapViewDelegate>
in .m file
mapView.delegate = self;

removeOverlay:overlay not working

I'm a new guy in the XCode realm and was wondering if someone could help me out.
Essentially, I'm playing around with WWDC2010's TileMap project example and am trying to figure out a way to hide their NOAA chart using a segmented controller.
I can activate the overlay and it displays fine, but I can't for the life of me remove it using a segmented controller.
Here's some code from the header file:
#interface ViewController : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *map;
IBOutlet UISegmentedControl *controller;
}
- (IBAction)switchMap:(id)sender;
#end
and here's the code for the .m:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"initial view loaded");
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay {
TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:overlay];
view.tileAlpha = 1;
return view;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)switchMap:(id)overlay {
if (controller.selectedSegmentIndex == 0) {
NSLog(#"welp... it loaded...");
[map removeOverlay:overlay];
}
if (controller.selectedSegmentIndex == 1) {
NSLog(#"Map Overlay works");
NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Tiles"];
TileOverlay *overlay = [[TileOverlay alloc] initWithTileDirectory:tileDirectory];
[map addOverlay:overlay];
MKMapRect visibleRect = [map mapRectThatFits:overlay.boundingMapRect];
visibleRect.size.width /= 2;
visibleRect.size.height /= 2;
visibleRect.origin.x += visibleRect.size.width / 2;
visibleRect.origin.y += visibleRect.size.height / 2;
map.visibleMapRect = visibleRect;
}
if (controller.selectedSegmentIndex == 2) {
NSLog(#"But... overlay isnt hiding waa");
NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Tiles"];
TileOverlay *overlay = [[TileOverlay alloc] initWithTileDirectory:tileDirectory];
[map removeOverlay:overlay]; }
}
In a control action method, the first parameter (no matter what you name it) is always the object that called the method.
Here, the control is a UISegmentedControl so the parameter that gets passed to switchMap: is a reference to that control. In the .h you've declared the parameter with the name sender but in the .m it's named overlay.
Regardless of the name, it's still the segmented control object so passing it to removeOverlay is meaningless and will do nothing.
So in this code:
if (controller.selectedSegmentIndex == 0) {
NSLog(#"welp... it loaded...");
[map removeOverlay:overlay];
}
overlay is pointing to the segmented control and so the removeOverlay does nothing.
In this code:
if (controller.selectedSegmentIndex == 2) {
NSLog(#"But... overlay isnt hiding waa");
NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Tiles"];
TileOverlay *overlay = [[TileOverlay alloc] initWithTileDirectory:tileDirectory];
[map removeOverlay:overlay]; }
You are creating a new local overlay object (the compiler is also probably giving you a warning about a local variable hiding the parameter). This new object is separate from the overlay that was already added to the map. Calling removeOverlay on this new object does nothing because this new instance was never added to the map in the first place.
To remove an existing overlay, you either have to keep an ivar reference to it when you add it and pass that ivar to remove or find it in the map view's overlays array.
However, if you will ever have only one overlay, you can pass the first object in the map view's overlays array or just call removeOverlays (plural) and pass the whole array:
if (map.overlays.count > 0)
[map removeOverlay:[map.overlays objectAtIndex:0]];
//OR...
if (map.overlays.count > 0)
[map removeOverlays:map.overlays];

Custom UIView with custom XIB: IBOutlets not working

I'm developing an iOS app with latest SDK and XCode 4.2.
I want to use a custom XIB in a custom UIView.
My custom UIView:
#interface CoordinateView : UIView {
/**
*/
ARGeoCoordinate *geoCoordinate;
/**
*/
IBOutlet UILabel* title;
/**
*/
IBOutlet UILabel* subTitle;
/**
*/
IBOutlet UIImageView* image;
}
Implementation:
#implementation CoordinateView
#synthesize geoCoordinate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code.
//
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"CoordinateView" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[CoordinateView class]])
{
[self addSubview:currentObject];
break;
}
}
}
return self;
}
- (id)initForCoordinate:(ARGeoCoordinate *)coordinate
{
self.geoCoordinate = coordinate;
CGRect theFrame = CGRectMake(0, 0, BOX_WIDTH, BOX_HEIGHT);
self = [self initWithFrame:theFrame];
if (self)
{
title.text = geoCoordinate.title;
image.image = [UIImage imageNamed:[NSString stringWithFormat:#"03%d.jpg", geoCoordinate.id]];
}
return self;
}
To initialize CoordinateView I use initWithCoordinate method.
Debugging I've found that title is nil here inside initWithCoordinate:
title.text = geoCoordinate.title;
I've used Interface Builder to 'link' IBOutlets.
What I'm doing wrong?
I ran into the same issue a while back. Here is what I did to fix it:
In the xib, open the document outline (the left pane that shows the list of views and their subviews etc).
Control left Click on the view representing your class (in your case CoordinateView) and drag the blue line down to the subviews (in your case the UILabel called title)
XCode should then bring up a small dialog box with the option "title" (because your label is called title.)
Click on title and wallaa.
Go back to your debugging and check if your outlets are still nil.
Just a personal preference (not necessarily related to the topic on discussion): I would call your UILabel 'titleLabel' instead of 'title' because [objectInstance title] looks like it would return an NSString to someone who does not know that 'title' is a UILabel. Just a personal preference, thats all.
Cheers
In your initWithFrame: method, you should assign self to currentObject instead of adding it as a subview.
Also there's no need to override initWithFrame: and calling the super method since the layout of your view is determined by your xib file.
When the view is totally loaded, the viewDidLoad method is called. So, you should initialize the elements within the view there:
- (void)viewDidLoad {
title.text = self.geoCoordinate.title;
}
More info in the docs.

Resources