Reputation: 330
Query 1: I'm using MKMapKit in which I want to display two location one is current location and another is a fixed location I use this code...
- (void)viewDidLoad
{
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,46,320,370)];
[mapView setDelegate:self];
[mapView setShowsUserLocation:TRUE];
[self.view addSubview:mapView];
[mapView setMapType:MKMapTypeStandard];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.9;
span.longitudeDelta=0.9;
CLLocationCoordinate2D location=mapView.userLocation.coordinate;
location.latitude=13.160407;
location.longitude=80.249562;
region.span=span;
region.center=location;
geoCoder =[[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
geoCoder.delegate = self;
[geoCoder start];
[super viewDidLoad];
}
- (MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation
{
NSLog(@"View for Annotation is called");
if (NSClassFromString(@"MKUserLocation")==[annotation class]) {
return nil;
}
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton * btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = btn;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
pindropped = TRUE;
//[map addAnnotations:annotation];
return annView;}
I Know this question has been posted many times,but I can't find any solution for my issue.......
Query 2: I need to plot the way between two locations in MPMapKit(as in google maps),How can I do tis???
Upvotes: 0
Views: 232
Reputation: 1145
1: You forgot your problem ;-) i assume, you don't see your location... there are two ways: mapview can show your location ->
mapView.showsUserLocation = YES
or you add a Annotation to the mapView :
[mapview addAnnotation:myLocation]
but please read the docs for mkmapview, your implementation is incomplete (missing delegates) and take a look at the examples
2: not as easy as on google maps javascript api. you have to draw lines from point to point. therefore you need the exact route from google.
Upvotes: 2