使用自定义引脚在地图视图(苹果地图)中显示用户的位置,并在用户名前面的表格视图中显示相同的引脚。每个用户应该有不同的引脚,如果用户名称出现两次,然后它应该具有与前一个相同的引脚颜色。
这是表视图屏幕截图,在此表视图下方有一个地图视图:
如果在表格视图中"用户名"然后在地图上有蓝色图钉"用户名" s"位置shud用蓝色针显示。 如果user2在表中有绿色引脚,那么它也应该是绿色的。
我得到的回应是
{
"driver_or_rider" = 1;
email = "ish@gmail.com";
isGuest = 0;
lat = "47.606209";
long = "-122.332071";
name = "ish bids";
"status_trip" = 1;
"user_image_url" = "http://app/image/1458101010.userimage";
},
{
"driver_or_rider" = 0;
email = "arin@gmail.com";
isGuest = 0;
lat = "34.052227";
long = "-118.243660";
name = "arin John";
"status_trip" = 1;
"user_image_url" = "http://app/image/5b3ee2e9fb51c7b20303a95b93bf63b2.";
},
{
"driver_or_rider" = 0;
email = "deepak12@gmail.com";
isGuest = 0;
lat = "31.968599";
long = "-99.901813";
name = "Deepak Chaudhary chaudhary ";
"status_trip" = 1;
"user_image_url" = "http://app/image/2197c75dc6b2bbd0ff26008a987781f3.";
},
{
"driver_or_rider" = 0;
email = "ish@gmail.com";
isGuest = 1;
lat = "31.968599";
long = "-99.901813";
name = "Deepak Chaudhary chaudhary 's Guest";
"status_trip" = 1;
"user_image_url" = "http://app/image/no-image.png";
},
{
"driver_or_rider" = 0;
email = "ish@gmail.com";
isGuest = 1;
lat = "41.878114";
long = "-87.629798";
name = "shiv Shankar 's Guest";
"status_trip" = 1;
"user_image_url" = "http://app/image/no-image.png";
},
{
"driver_or_rider" = 0;
email = "shiv@gmail.com";
isGuest = 0;
lat = "41.878114";
long = "-87.629798";
name = "shiv Shankar ";
"status_trip" = 1;
"user_image_url" = "http://app/image/1458129359.userimage";
},
{
"driver_or_rider" = 0;
email = "andrew.payasi@gmail.com";
isGuest = 0;
lat = "43.65322577127058";
long = "-79.38318371772766";
name = username;
"status_trip" = 1;
"user_image_url" = "http://app/image/1456821877.png";
}
)
这是索引
行的单元格中的代码int randomNumber = indexPath.row%[imageNameArray count];
NSString* nameStr=[goersInfo valueForKey:@"name"];
NSArray * nameStrArray = [nameStr componentsSeparatedByString: @"'s"];
nameStr=[nameStrArray objectAtIndex:0];
NSNumber *indexNumber = self.pinDictionary[nameStr];
index = indexNumber.unsignedIntegerValue;
cell.PinImageView.image=[UIImage imageNamed:[imageNameArray objectAtIndex:index]];
这是存储名称的字典
- (void)setupPinDictionary
{
self.pinDictionary = [NSMutableDictionary dictionary];
self.imageNameArray = [[NSArray alloc] initWithObjects:@"pin2@2x.png", @"pin3@2x.png", @"pin4@2x.png", @"pin5@2x.png", @"pin6@2x.png",@"pin8@2x.png",@"pin9@2x.png", nil];
NSUInteger pinImageCount = self.imageNameArray.count;
for (NSDictionary *goersInfo in tableGoersList) {
NSString* nameStr=[goersInfo valueForKey:@"name"];
NSArray * nameStrArray = [nameStr componentsSeparatedByString: @"'s"];
nameStr=[nameStrArray objectAtIndex:0];
if (self.pinDictionary[nameStr] == nil) {
indexPin = arc4random() % pinImageCount;
self.pinDictionary[nameStr] = [NSNumber numberWithUnsignedInteger: indexPin];
}
}
最初这个方法叫做
-(void)doJourneyGoersList:(id)responseObject{
NSDictionary *dict=[responseObject[@"Count"] firstObject];
checkLocation=[[NSMutableArray alloc]init];
if (dict==nil) {
return;
}
[_messagesButton.badgeButton setBadgeValue:dict[@"Count_Masssage"]];
[_invitesButton.badgeButton setBadgeValue:dict[@"invite_count"]];
[_matchedButton.badgeButton setBadgeValue:dict[@"Count_Match"]];
goersList= [responseObject objectForKey:@"statement"];
CLLocationCoordinate2D orginCllocation=CLLocationCoordinate2DMake([_tripDetails[@"origin_lat"] doubleValue], [_tripDetails[@"origin_long"] doubleValue]);
MKPointAnnotation *annotation =[[MKPointAnnotation alloc] init];
annotation.coordinate=orginCllocation;
[checkLocation addObject:annotation];
tableGoersList=[NSMutableArray new];
for (NSDictionary *dict in goersList) {
NSMutableDictionary *localdict=[NSMutableDictionary new];
loc=[NSMutableDictionary new];
[localdict setObject:[dict objectForKey:@"name"] forKey:@"name"];
[localdict setObject:[dict objectForKey:@"email"] forKey:@"email"];
if ([dict[@"status_trip"] isEqualToString:@"confirm"]) {
[localdict setObject:@"1" forKey:@"status_trip"];
[loc setObject:[dict objectForKey:@"origin_lat"] forKey:@"lat"];
[loc setObject:[dict objectForKey:@"origin_long"] forKey:@"long"];
CLLocationCoordinate2D location=CLLocationCoordinate2DMake([loc[@"lat"] doubleValue], [loc[@"long"] doubleValue]);
[localdict setObject:[dict objectForKey:@"origin_lat"] forKey:@"lat"];
[localdict setObject:[dict objectForKey:@"origin_long"] forKey:@"long"];
if (location.latitude == orginCllocation.latitude && location.longitude == orginCllocation.longitude) {
//location is origin, skip this since it is already added
} else {
MKPointAnnotation *annotation =[[MKPointAnnotation alloc] init];
annotation.coordinate=location;
[checkLocation addObject: annotation];
}
NSLog(@"check location %@",checkLocation);
}
else
[localdict setObject:@"0" forKey:@"status_trip"];
if ([dict[@"isGuest"] isEqualToString:@"1"]) {
[localdict setObject:@"1" forKey:@"isGuest"];
}
else
[localdict setObject:@"0" forKey:@"isGuest"];
[localdict setObject:[dict objectForKey:@"user_image_url"] forKey:@"user_image_url"];
if ([dict[@"driver_or_rider"] isEqualToString:@"Drive"]) {
[localdict setObject:@"1" forKey:@"driver_or_rider"];
[tableGoersList insertObject:localdict atIndex:0];
}
else
{
[localdict setObject:@"0" forKey:@"driver_or_rider"];
[tableGoersList addObject:localdict];
}
//add the objects to the array
}
CLLocationCoordinate2D parkCllocation=CLLocationCoordinate2DMake([_tripDetails[@"park_lat"] doubleValue], [_tripDetails[@"park_long"] doubleValue]);
MKPointAnnotation *jauntAnnotationPark =[[MKPointAnnotation alloc] init];
jauntAnnotationPark.coordinate=parkCllocation;
[checkLocation addObject:jauntAnnotationPark];
[mapView showAnnotations: checkLocation animated:NO];
[mapView setCenterCoordinate:mapView.region.center animated:NO];
int count = [checkLocation count];
CLLocationCoordinate2D coordinateArray[count];
for (int i = 0; i < count; i++) {
coordinateArray[i] = ((MKPointAnnotation *)checkLocation[i]).coordinate;
}
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:count];
[mapView addOverlay:self.routeLine];
[self setupPinDictionary];
[self.ridersTableView reloadData];
}
这是注释视图的代码
{
imageNameArray = [[NSArray alloc] initWithObjects:@"pin2@2x.png", @"pin3@2x.png", @"pin4@2x.png", @"pin5@2x.png", @"pin6@2x.png",@"pin8@2x.png",@"pin9@2x.png",nil];
[self setupPinDictionary];
myAnnotation.image=[UIImage imageNamed:[imageNameArray objectAtIndex:indexPin]];
}
return myAnnotation;
}