Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

fixed to support other language data from .csv file #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions TBAnnotationClustering/TBCoordinateQuadTree.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ TBQuadTreeNodeData TBDataFromLine(NSString *line)

TBHotelInfo* hotelInfo = malloc(sizeof(TBHotelInfo));

NSString *hotelName = [components[2] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
hotelInfo->hotelName = malloc(sizeof(char) * hotelName.length + 1);
strncpy(hotelInfo->hotelName, [hotelName UTF8String], hotelName.length + 1);

NSString *hotelPhoneNumber = [[components lastObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
hotelInfo->hotelPhoneNumber = malloc(sizeof(char) * hotelPhoneNumber.length + 1);
strncpy(hotelInfo->hotelPhoneNumber, [hotelPhoneNumber UTF8String], hotelPhoneNumber.length + 1);
const char *hotelName = [[components[2] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] UTF8String];
size_t hotelNameLength = strlen(hotelName) + 1;
hotelInfo->hotelName = malloc(hotelNameLength);
memset(hotelInfo->hotelName, 0, hotelNameLength);
strncpy(hotelInfo->hotelName, hotelName, hotelNameLength);

const char *hotelPhoneNumber = [[[components lastObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] UTF8String];
size_t hotelPhoneNumberLength = strlen(hotelPhoneNumber) + 1;
hotelInfo->hotelPhoneNumber = malloc(hotelPhoneNumberLength);
memset(hotelInfo->hotelPhoneNumber, 0, hotelPhoneNumberLength);
strncpy(hotelInfo->hotelPhoneNumber, hotelPhoneNumber, hotelPhoneNumberLength);

return TBQuadTreeNodeDataMake(latitude, longitude, hotelInfo);
}
Expand Down Expand Up @@ -90,7 +94,7 @@ @implementation TBCoordinateQuadTree
- (void)buildTree
{
@autoreleasepool {
NSString *data = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"USA-HotelMotel" ofType:@"csv"] encoding:NSASCIIStringEncoding error:nil];
NSString *data = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"USA-HotelMotel" ofType:@"csv"] encoding:NSUTF8StringEncoding error:nil];
NSArray *lines = [data componentsSeparatedByString:@"\n"];

NSInteger count = lines.count - 1;
Expand Down Expand Up @@ -133,8 +137,8 @@ - (NSArray *)clusteredAnnotationsWithinMapRect:(MKMapRect)rect withZoomScale:(do
count++;

TBHotelInfo hotelInfo = *(TBHotelInfo *)data.data;
[names addObject:[NSString stringWithFormat:@"%s", hotelInfo.hotelName]];
[phoneNumbers addObject:[NSString stringWithFormat:@"%s", hotelInfo.hotelPhoneNumber]];
[names addObject:[NSString stringWithFormat:@"%@", [NSString stringWithUTF8String:hotelInfo.hotelName]]];
[phoneNumbers addObject:[NSString stringWithFormat:@"%@", [NSString stringWithUTF8String:hotelInfo.hotelPhoneNumber]]];
});

if (count == 1) {
Expand Down