#import "GoogleMap.h"
#import "MyAnnotation.h"
@implementation GoogleMap
- (void)viewDidLoad {
[super viewDidLoad];
variable1 = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"NewYorkAreas"
ofType:@"plist"]];
double minLat = [[variable1 valueForKeyPath:@"@min.latitude"] doubleValue];
double maxLat = [[variable1 valueForKeyPath:@"@max.latitude"] doubleValue];
double minLon = [[variable1 valueForKeyPath:@"@min.longitude"] doubleValue];
double maxLon = [[variable1 valueForKeyPath:@"@max.longitude"] doubleValue];
MKCoordinateRegion region;
region.center.latitude = (maxLat + minLat) / 2.0;
region.center.longitude = (maxLon + minLon) / 2.0;
region.span.latitudeDelta = (maxLat - minLat) * 1.05;
region.span.longitudeDelta = (maxLon - minLon) * 1.05;
map.region = region;
for (NSDictionary *newYorkAreasDict in variable1){
MyAnnotation *annotation = [[MyAnnotation alloc] initWithDictionary:newYorkAreasDict];
[map addAnnotation:annotation];
[annotation release];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if (map.userLocation == annotation){
return nil;
}
NSString *identifier = @"MY_IDENTIFIER";
MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil){
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:identifier]
autorelease];
annotationView.image = [UIImage imageNamed:@"logo.png"];
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
return annotationView;
}
所以现在,我想实现用户的位置并绘制用户位置和我公司之间的路线,但我不知道如何编码,所以我希望有人可以帮助我,谢谢!