[OGo-Developer] NSURL different in libFoundation and GNUstep base?
Sebastian Reitenbach
developer@opengroupware.org
Sun, 13 Apr 2008 09:16:21 +0200
Hi,
i try to create a NSURL and then to retrieve some data from it. This is
working with my test program on gnustep-base, but not with libFoundation.
below are the two test program sources, and their output. In gnustep-base
environment, everything is working as I expect it, with libFoundation, it
acts strange. Does anybody know, what I'm missing, or whats wrong with my
code for libFoundation?
here the code I run with gnustep-base:
#include <Foundation/Foundation.h>
int
main(int argc, const char *argv[])
{
id pool = [[NSAutoreleasePool alloc] init];
NSString *GKey =
@"ABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A";
NSString *Address = @"Potsdamer+Platz+Berlin+Germany";
NSString *URLString = [NSString
stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv&key=%@",
Address, GKey];
URLString = [URLString
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"URL: %@", URLString);
NSURL *url = [NSURL URLWithString:URLString];
NSLog(@"NSURL *url: %@", url);
NSString *coordinates = [NSString stringWithContentsOfURL:url];
NSArray *coordItems = [coordinates componentsSeparatedByString:@","];
NSLog(@"Latitude: %@ Longitude: %@", [coordItems objectAtIndex:2],
[coordItems objectAtIndex:3]);
NSString *GeoCacheURL = [NSString
stringWithFormat:@"http://www.geocaching.com/seek/nearest.aspx?origin_lat=%@&origin_long=%@",
[coordItems objectAtIndex:2], [coordItems objectAtIndex:3]];
NSLog(@"NewURL: %@", GeoCacheURL);
[pool release];
return 0;
}
and here the output:
2008-04-13 09:14:26.520 getcoords[17352] URL:
http://maps.google.com/maps/geo?q=Potsdamer+Platz+Berlin+Germany&output=csv&key=ABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A
2008-04-13 09:14:26.522 getcoords[17352] NSURL *url:
http://maps.google.com/maps/geo?q=Potsdamer+Platz+Berlin+Germany&output=csv&key=ABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A
2008-04-13 09:14:33.466 getcoords[17352] Latitude: 52.509328 Longitude:
13.375837
2008-04-13 09:14:33.466 getcoords[17352] NewURL:
http://www.geocaching.com/seek/nearest.aspx?origin_lat=52.509328&origin_long=13.375837
here the code I run with libFoundation:
#include <Foundation/Foundation.h>
#include <NGExtensions/NSString+misc.h>
int
main(int argc, char **argv, char **envp)
{
[NSProcessInfo initializeWithArguments:argv count: argc environment:
envp];
id pool = [[NSAutoreleasePool alloc] init];
NSString *GKey =
@"ABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A";
NSString *Address = @"Potsdamer+Platz+Berlin+Germany";
NSString *URLString = [NSString
stringWithFormat:@"maps.google.com:80/maps/geo?q=%@&output=csv&key=%@",
Address, GKey];
// URLString = [URLString
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
URLString = [URLString stringByEscapingURL];
URLString = [@"http://" stringByAppendingString:URLString];
NSLog(@"URL: %@", URLString);
NSURL *url = [NSURL URLWithString:URLString];
NSLog(@"NSURL *url: %@", url);
NSString *coordinates = [NSString stringWithContentsOfURL:url];
NSArray *coordItems = [coordinates componentsSeparatedByString:@","];
NSLog(@"Latitude: %@ Longitude: %@", [coordItems objectAtIndex:2],
[coordItems objectAtIndex:3]);
NSString *GeoCacheURL = [NSString
stringWithFormat:@"http://www.geocaching.com/seek/nearest.aspx?origin_lat=%@&origin_long=%@",
[coordItems objectAtIndex:2], [coordItems objectAtIndex:3]];
NSLog(@"NewURL: %@", GeoCacheURL);
[pool release];
return 0;
}
and the corresponding output:
Apr 13 07:00:50 getcoords [13768]: URL:
http://maps.google.com%3A80%2Fmaps%2Fgeo%3Fq%3DPotsdamer%2BPlatz%2BBerlin%2BGermany%26output%3Dcsv%26key%3DABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A
Apr 13 07:00:50 getcoords [13768]: NSURL *url: <_NSAbsoluteHTTPURL
0x89620244:
'http://maps.google.com%3A80%2Fmaps%2Fgeo%3Fq%3DPotsdamer%2BPlatz%2BBerlin%2BGermany%26output%3Dcsv%26key%3DABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A:80/'>
Apr 13 07:00:50 getcoords [13768]: -[NSURL URLHandleUsingCache:]: missing
handler for URL '<_NSAbsoluteHTTPURL
0x89620244:
'http://maps.google.com%3A80%2Fmaps%2Fgeo%3Fq%3DPotsdamer%2BPlatz%2BBerlin%2BGermany%26output%3Dcsv%26key%3DABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A:80/'>'
Uncatched Objective-C exception:
exceptionClass <class RangeException>
Reason: objectAtIndex: in NSArray
UserInfo: {
index = 3;
size = 1;
}
libFoundation adds a :80 to the end of the URL, I wonder why, and whether
this is the problem?
kind regards
Sebastian