-
Notifications
You must be signed in to change notification settings - Fork 1
/
GPSPoint.m
74 lines (62 loc) · 2.06 KB
/
GPSPoint.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// Point.m
// GPSLogger
//
// Created by German Laullon on 03/10/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "GPSPoint.h"
#import "TrackNode.h"
@implementation GPSPoint
@synthesize index;
@synthesize latitud;
@synthesize longitud;
@synthesize fecha;
@synthesize altitud;
@synthesize velocidad;
@synthesize tag;
@synthesize track;
- (NSComparisonResult)compare:(GPSPoint *)anotherGPSPoint
{
return [fecha compare:[anotherGPSPoint fecha]];
}
-(NSString *)getAddress:(NSString *)alt
{
NSError *error=nil;
NSDictionary *args=[NSDictionary dictionaryWithObjectsAndKeys:
@"true",@"sensor",
[NSString stringWithFormat:@"%@,%@",[self latitud],[self longitud]],@"latlng",
nil];
NSURL *url=[NSURL URLWithString:[self prepareURL:@"http://maps.google.com/maps/api/geocode/xml" params:args]];
NSLog(@"getAddress url => %@",url);
NSXMLDocument *doc=[[NSXMLDocument alloc] initWithContentsOfURL:url
options:(NSXMLNodePreserveWhitespace|NSXMLNodePreserveCDATA)
error:&error];
if(error)
{
NSLog(@"%@:%@ Error saving context: %@", [self class], NSStringFromSelector(_cmd), [error localizedDescription]);
}
NSString *xq=[[NSBundle mainBundle] pathForResource:@"google_city" ofType:@"xq"];
NSArray *cities=[doc objectsForXQuery:[NSString stringWithContentsOfFile:xq encoding:NSUTF8StringEncoding error:nil] error:&error];
if(error || [cities count]<1)
{
NSData *xml=[doc XMLDataWithOptions:NSXMLNodePrettyPrint];
NSLog(@"XML Document\n%@", [NSString stringWithCString:[xml bytes] encoding:NSUTF8StringEncoding]);
NSLog(@"%@:%@ error: %@", [self class], NSStringFromSelector(_cmd), [error localizedDescription]);
return alt;
}
if([cities count]>0){
NSLog(@"---> %@",[cities objectAtIndex:0]);
return [cities objectAtIndex:0];
}
return alt;
}
- (NSString *)prepareURL:(NSString *)url params:(NSDictionary *)args
{
NSMutableString *res=[[NSMutableString alloc] init];
[res appendFormat:@"%@?",url];
for(id key in args)
[res appendFormat:@"&%@=%@",key,[args objectForKey:key]];
return res;
}
@end