neilang / NAMapKit

Allows you to use custom maps in iphone applications and attempts to mimics some of the behaviour of the MapKit framework
MIT License
263 stars 52 forks source link

Create Pin annotation for my swift project using NAMapkit #52

Closed saravananNV closed 8 years ago

saravananNV commented 8 years ago

This was my code i have an image named floor_map as local image

I am very new to IOS The pinannotation was not working but dotannotation was working perfect with same x and y co-ordinates.May be i dont know how to use this for pin annotation and also i want to show an image which replace the pin.can some one please help me.i am stuck

 let mapView: NAMapView = NAPinAnnotationMapView(frame: self.view.bounds)
    mapView.backgroundColor = UIColor.whiteColor()
    mapView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
    mapView.minimumZoomScale = 0.5
    mapView.maximumZoomScale = 1.5
    mapView.displayMap(UIImage(named: "floor_map"))
    self.view!.addSubview(mapView)
    let melbourne: NAPinAnnotation = NAPinAnnotation()
    melbourne.color = NAPinColorPurple
    melbourne.title = "Melbourne"
    melbourne.subtitle = "I have a subtitle"
    melbourne.point = CGPoint(x: 543.0, y: 450.0)
    mapView.addAnnotation(melbourne, animated: false)
dblock commented 8 years ago

IMO it should "just work", maybe put together a dummy project that shows the issue? Do look through the demo code in this repo that definitely works correctly with a pin annotation.

saravananNV commented 8 years ago

Ofcourse, I have seen the demo project and use the code form the file NAPinAnnotationsDemoViewController which was used to create pin..the only difference was i converted into swift..but my effort was in vain. i have attached the sample project here.i working around with two days..but i dont get any lead.

Thankyou

sample.zip

dblock commented 8 years ago

@saravananNV Instead of a zip, maybe put your project on Github, open an issue and link from here. Me or someone else will take a look when we get a chance. Maybe you'll get a PR with a fix ;)

saravananNV commented 8 years ago

@dblock ..thank u..here is the git hub link of the project

https://github.com/saravananNV/NaMapkit

Thanks Guys,

orta commented 8 years ago

could be because the pin assets are inside a separate bundle now, and they may have been using UIImage imageNamed:

saravananNV commented 8 years ago

Hi Orta, I have given my git hub project link above which use NAMapkit frame work. can you please see that and tell me where i am wrong.

Help will be appreciated

Thanks Guys

dblock commented 8 years ago

I put a breakpoint in the loading of the image in https://github.com/neilang/NAMapKit/blob/master/NAMapKit/NAPinAnnotationView.m#L56, and that's exactly the problem, the image isn't loaded from the bundle.

    UIImage *pinImage = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingString:pinImageName]];
    [self setImage:pinImage forState:UIControlStateNormal];

This ends up being something like "/Users/dblock/Library/Developer/CoreSimulator/Devices/6171C10F-67C0-471D-B74B-7E4149ACDF69/data/Containers/Bundle/Application/A14D79BC-8942-407D-B9B3-C6D4E2D24639/sample.app/pin_purple.png" which is incorrect, it's missing "Frameworks/NAMapKit.framework" in the path.

@orta Do you know the right way to fix this?

orta commented 8 years ago

[NSBundle mainBundle] bundlePath] wants to changes for [NSBundle mainBundle] bundleForClass:NAMapKit.class]

dblock commented 8 years ago

@saravananNV Want to try to fix this in this project and submit a pull request?

saravananNV commented 8 years ago

Is there is any way to fix this bug?.. or you guys working on it.i have to use this wonderful mapkit in our project with in two days.thats y , i am trying it to work on pinAnnotation with this sample app for a trial..

Thanks

dblock commented 8 years ago

Fix the bug by changing the code in NAMapKit as orta suggests above. Submit a pull request with the fix after you've tested it.

saravananNV commented 8 years ago

when i try to change that particular line.it shows the below error:

No visible @interface for 'NSBundle' declares the selector 'bundleForClass:'

I cant use bundleforclass. for my version i can use only bundlepath,bundleurl and bundleIdentifier

orta commented 8 years ago

@saravananNV - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/index.html#//apple_ref/occ/clm/NSBundle/bundleForClass:

saravananNV commented 8 years ago

HI Orta & dblock

hey, guys i fxed it....i modified the line on https://github.com/neilang/NAMapKit/blob/master/NAMapKit/NAPinAnnotationView.m#L56 by

NSString * image = _animating ? [NSString stringWithFormat:@"%@Floating", pinImageName] : pinImageName; [self setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];

which is from https://github.com/nicked/NAMapKit/blob/master/NAMapKit/NAPinAnnotationView.m line 58

orta commented 8 years ago

@saravananNV - I'm afraid I don't have the time to hold your hand through using this library.

saravananNV commented 8 years ago

@orta , you and @dblock have spend your valuable time with me. all my issues are fixed..last task was how can i change images for pin annotation.just give me a lead.then i will work on it.sorry to disturb u @orta

thanks

dblock commented 8 years ago

I think if you want to change the images you might want to either subclass the annotation class or roll out your own.

dblock commented 8 years ago

Would appreciate a pull request with your fix, please @saravananNV.

saran-metron commented 8 years ago

@dblock and @orta there is no image porperty on Annotation class.then how can i change the image instead of pin

saravananNV commented 8 years ago

@dblock and @orta i have created a custom class which inherits the annotation and override the function createviewonmapview.but how to integrate this function which explicit my new view and also how to set image for customized pin. i know that i am troubling you too. i am stuck.thats y..please help me

thanks,

dblock commented 8 years ago

@saran-metron and @saravananNV - you're not getting much help here because you're asking for fairly basic things, and I totally understand that you're just starting programming in Objective-C, but people contributing to this project don't really have time to teach you the basics. I suggest finding a friend or colleague who's a bit more experienced and pairing with them on this. I am sorry I cannot be of much more help - when/if I have time I'll write up some more examples.

dblock commented 8 years ago

Fixed via https://github.com/neilang/NAMapKit/commit/ce7ed0797c7b41056d01aa1390026874e7421b0a.