English 中文(简体)
你们如何在地图上创造多彩的皮条?
原标题:How do you create multi colored pins in a map?

我的地图需要显示“Venues”和“BLUE”在附近和周围的“Parking Lots”。

The problem is that both pins show up in the same color.

该守则如下:

我的温和派认为:

#import <MapKit/MapKit.h>


@interface mapPinAnnotation : NSObject  <MKAnnotation>  {    
    NSString *title;
    NSString *subtitle;
    NSString *pinType; // this string will be set to either "Venue" or "Parking"
    CLLocationCoordinate2D coordinate;
}


@property (nonatomic, retain) NSString *title, *subtitle;
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *pinType;


@end

执行:

#import "mapPinAnnotation.h"

@implementation mapPinAnnotation

@synthesize coordinate;
@synthesize pinType;
@synthesize title, subtitle;

-(id) initWithCoordinate: (CLLocationCoordinate2D) c {
    coordinate = c;
    return self;
}    

@end

这里指的是确定“表象”的方法——我注意到我使用一个“表象”变量——在全球宣布——因此,我可以把这个词推到“概览”方法中,但我认为,问题是:

-(void) dropThePin {
    CLLocationCoordinate2D location = mapView.userLocation.coordinate;

    location.latitude = latitude;
    location.longitude = longitude;        

    if(pinAnnotation != nil) {
        [mapView removeAnnotation:pinAnnotation];
        [pinAnnotation release];
        pinAnnotation = nil;
    }

    // Create (alloc/init) a Pin, set its Title & Subtitle, and add/place it:
    pinAnnotation = [[mapPinAnnotation alloc] initWithCoordinate:location];
    pinAnnotation.pinType = @"VENUE";

    tempPin = pinAnnotation;

    [pinAnnotation setTitle: @"Some Stadium"];
    [pinAnnotation setSubtitle: @"123 Main St."];

    [mapView addAnnotation:pinAnnotation];


    // Set-Up of 2nd. Pin:
    location.latitude = 12.34567;
    location.longitude = -23.45678;

    pinAnnotation.pinType = @"PARKING";
    if(parkingLotPin != nil) {
        [mapView removeAnnotation:parkingLotPin];
        [parkingLotPin release];
        parkingLotPin = nil;
    }

    // Create (alloc/init) a Pin, set its Title & Subtitle, and add/place it:
    parkingLotPin = [[mapPinAnnotation alloc] initWithCoordinate:location];

    tempPin = pinAnnotation;
    [parkingLotPin setTitle: @"Another Venue"];
    [parkingLotPin setSubtitle: @"789 S. Broad Street"];

    [mapView addAnnotation:parkingLotPin];
    [parkingLotPin release];

}

最后,这里是“观点”方法:

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation {

    MKPinAnnotationView *thePin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];

    if (tempPin.pinType == @"VENUE") {
        thePin.pinColor = MKPinAnnotationColorGreen;
        NSLog(@"pin-type = %@", tempPin.pinType);
    } else {
        thePin.pinColor = MKPinAnnotationColorPurple;
        NSLog(@"pin-type = %@", tempPin.pinType);
    }

    thePin.animatesDrop=TRUE;
    thePin.canShowCallout = YES;
    thePin.calloutOffset = CGPointMake(-5, 5);
    return thePin;
}

问题在于,这两种颜色都有相同的颜色。

任何建议?

最佳回答

变化:

if (tempPin.pinType == @"VENUE") {

:

if ([((mapPinAnnotation*)annotation).pinType isEqualToString:@"VENUE"]) {
问题回答
if ([tempPin.pinType isEqualToStirng:@"VENUE"]) {
    thePin.pinColor = MKPinAnnotationColorGreen;
    NSLog(@"pin-type = %@", tempPin.pinType);
} else {
    thePin.pinColor = MKPinAnnotationColorPurple;
    NSLog(@"pin-type = %@", tempPin.pinType);
}

http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#/apple_ref/doc/uid/TP40009497-CH6-SW33“rel=” 另见。





相关问题
Selecting Links in Google Maps InfoWindows w/ jQuery

In my web app, I am using jQuery to select all the links on the page and intercept where they go to so that I can switch to a different part of the page with AJAX. The problem is that some of these ...

Add custom control to Subgurim Maps

Is it possible to add a custom control to the GMap control in the Subgurim library? I see that I can add a GControl with the GMap.AddControl method. I tried to create a custom GControl by ...

Changing the value in a map in Groovy

This is about a very basic program I m writing in Groovy. I have defined a map inside a method: def addItem() { print("Enter the item name: ") def itemName = reader.readLine() print(...

Best way to store and retrieve this..?

I ve been trying all night, and talk of maps, arrays, vectors and hash_maps have filled my head. im just confused now. i posted a previous question here: C++ map really slow? problem was fixed but it ...

热门标签