At first glance it looks correct. Is Build Action for pin.png set to Content? Can you make sure they are actually copied to the .app package? (there's a bug in some versions of MonoDevelop where images would not be copied).
Mikkel P.S. Replied to all. On Mon, Sep 5, 2011 at 15:32, Tomasz Cielecki <[email protected]> wrote: > I think your suggestion is more or less the same way I am implementing it. > > Code can be seen here https://gist.github.com/1194994 or: > > Here is my Main.cs file: > using System; > using System.Collections.Generic; > using System.Linq; > using MonoTouch.Foundation; > using MonoTouch.UIKit; > using LoadSiteList; > using MonoTouch.MapKit; > using MonoTouch.CoreLocation; > > namespace MapsStuff > { > > > public class Application > { > static void Main (string[] args) > { > UIApplication.Main (args); > } > } > > > // The name AppDelegate is referenced in the MainWindow.xib file. > public partial class AppDelegate : UIApplicationDelegate > { > UITabBarController tabBarController; > os4MapsViewController viewController; > MapsStuff.TableViewController viewController2; > > > // This method is invoked when the application has loaded > its UI and > its ready to run > public override bool FinishedLaunching (UIApplication app, > NSDictionary options) > { > window = new UIWindow (UIScreen.MainScreen.Bounds); > tabBarController = new UITabBarController(); > > viewController = new os4MapsViewController(); > viewController2 = new TableViewController(); > > viewController.TabBarItem = new UITabBarItem ("Map", > UIImage.FromFile("Images/103-map.png"), 0); > viewController2.TabBarItem = new UITabBarItem > ("List", > UIImage.FromFile("Images/103-map.png"), 0); > tabBarController.ViewControllers = new > UIViewController[] > {viewController, viewController2}; > > window.AddSubview(tabBarController.View); > // If you have defined a view, add it here: > // window.AddSubview (navigationController.View); > > window.MakeKeyAndVisible (); > > return true; > } > > // This method is required in iPhoneOS 3.0 > public override void OnActivated (UIApplication application) > { > } > } > } > > Next here is the os4MapsViewController.cs: > > using System; > using System.Drawing; > using System.Collections.Generic; > using System.Diagnostics; > using MonoTouch.Foundation; > using MonoTouch.UIKit; > using MonoTouch.MapKit; > using MonoTouch.CoreLocation; > > namespace MapsStuff > { > public class os4MapsViewController: UIViewController > { > private MKMapView _mapView { get; set; } > List<MapsStuff.MapAnnotation> pins; > > public MKMapView MapView > { > get { return _mapView; } > } > > public os4MapsViewController () : base() > {} > > public override void ViewDidLoad () > { > base.ViewDidLoad (); > > // > // Create our map view and add it as as subview. > // > pins = CreateRandomPins(); > _mapView = new MKMapView(); > _mapView.Frame = new RectangleF (0, 0, > this.View.Frame.Width, > this.View.Frame.Height); > _mapView.ShowsUserLocation = true; > _mapView.MapType = MKMapType.Hybrid; > _mapView.Delegate = new MapViewDelegate(); > foreach (MapAnnotation m in pins) > { > _mapView.AddAnnotation(m); > } > View.AddSubview(_mapView); > } > > List<MapsStuff.MapAnnotation> CreateRandomPins() > { > Random r = new Random(); > List<MapsStuff.MapAnnotation> locations = new > List<MapsStuff.MapAnnotation>(); > for (int i = 0; i < 4; i++) > { > locations.Add( > new MapsStuff.MapAnnotation( > new > CLLocationCoordinate2D(r.NextDouble() * 180, > r.NextDouble() * 180), > "test" + i, > "sub" + i > )); > } > > return locations; > } > } > public class MapViewDelegate : MKMapViewDelegate > { > public MapViewDelegate (): base() > { > } > public override MKAnnotationView GetViewForAnnotation > (MKMapView > mapView, NSObject annotation) > { > var anv = > mapView.DequeueReusableAnnotation("thislocation"); > if (anv == null) > { > Console.WriteLine("creating new > MKAnnotationView"); > anv = new MKPinAnnotationView(annotation, > "thislocation"); > } > else > { > anv.Annotation = annotation; > } > anv.Image = new UIImage("pin.png"); > anv.CanShowCallout = true; > return anv; > } > } > } > > So both the referenced images in Main.cs and the ones in > os4MapsViewController.cs are not shown > http://imageshack.us/photo/my-images/850/screenshot20110905at323.png/ > <-- this image shows what I get on the emulator. > > pin.png lies in the root folder of my project. The other image lies in > the folder Images in the project dir. None of them seems to show up. > > Any ideas? I know the code provided uses MKPinAnnotationView, but > changing it to MKAnnotationView simply shows nothing. > > On Mon, Sep 5, 2011 at 2:48 PM, Mikkel Lønow <[email protected]> wrote: > > Hi Tomasz, > > I believe MKAnnotationView would be your best option. Use a custom > > MKMapViewDelegate and override GetViewForAnnotation where you call > > mapView.DequeueReusableAnnotation to reuse the annotation view (or create > a > > new if null). Here you can set your image to the annotation view. > > Feel free to share your implementation if you need more help. > > Mikkel > > > > On Mon, Sep 5, 2011 at 14:01, Tomasz Cielecki <[email protected]> > wrote: > >> > >> Hello MonoTouch list, > >> > >> I am in the midst of creating a iPhone app where I need a map with > >> some circles, where the circle colors changes depending on the data > >> received asynchronously in the background. > >> > >> So my first approach to this was to get a Map shown on the devices > >> with a circle, which works fine. Only problem is that MKCircle takes a > >> radius for that circle, which means the circle is only visible at some > >> zoom level. So lets say the circle radius is 100 meters, then I have > >> to zoom to almost the biggest zoom level to get to a point where I > >> actually can see the circle, this is not the desirable behavior. I > >> want to have the circle resize along with the zoom level, just like > >> pins do. > >> > >> So I have also tried to use a custom image on MKPinAnnotationView and > >> on MKAnnotationView, neither of them seems to show my custom image. > >> The normal pin image shows when using MKPinAnnotationView. I have put > >> the pin image in the root of my project and referencing it with the > >> path "pin.png" (the name of the image is actually pin.png). > >> > >> So maybe someone here can help me find out what is wrong, or provide > >> me with some examples on how to do this? I would prefer if I could use > >> MKCircle and just choose the color. But using images could be a > >> solution. > >> > >> -- > >> Med Venlig Hilsen / With Best Regards > >> Tomasz Cielecki > >> http://ostebaronen.dk > >> _______________________________________________ > >> MonoTouch mailing list > >> [email protected] > >> http://lists.ximian.com/mailman/listinfo/monotouch > > > > > > > > -- > Med Venlig Hilsen / With Best Regards > Tomasz Cielecki > http://ostebaronen.dk >
_______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
