How to add new property to the Gmsmarker class?

Asked

Viewed 31 times

0

Adding a new property to this class.

I added it to the Gmsmarker. h file, but while trying to use the new property I received this error:

-[Gmsmarker setIdRegister:]: unrecognized selector sent to instance 0x790cd410 2015-02-27 13:26:44.340 Testeparking[7174:108607] *** Terminating app due to uncaught Exception 'Nsinvalidargumentexception', Report: '-[Gmsmarker setIdRegister:]: unrecognized selector sent to instance 0x790cd410'

  • Any special reason why you want to change the class of your own Google Maps library? I don’t know if it’s possible the way you want it to be.

  • Yes add one more attribute to save information related to the location it indicates on the map. Jaja I will show you how I did it. But it’s no big deal.

  • Uses the attribute that exists in Gmsmarker called userData

1 answer

0


I managed to resolve by declaring a new class, inheriting Gmsmarker.

In the declaration of the new class I included the new desired property, and then synthesized it.

MeuMarker.h

#import <GoogleMaps/GoogleMaps.h>

@interface MeuMarker : GMSMarker

@property (nonatomic, strong) NSString* idRegistroTocado;

@end

Meumarker. m

#import "MeuMarker.h"

@implementation MeuMarker

@synthesize idRegistroTocado;

@end

Utilizing

MeuMarker* marker = [[MeuMarker alloc]init];

marker.position = position;
marker.title = dadosRegistros.nome;
marker.snippet = dadosRegistros.rua;
marker.idRegistroTocado = dadosRegistros.idRegistro;
  • You could have just used the attribute: userData

  • I did not know about this attribute, I even looked for something about but I did not. But I needed to use more of a new information. And so I was able to expand the use. But if this attribute is a Nsmutablearray, I will consider its use in future projects and even update this one. Thank you!

  • Yeah, it actually works like the NSDictionary, key - value, enabling multiple attributes, an example: marker.userData = @{@"store":info};

  • Great! Thank you @Gian! I’ll add the answer!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.