开发者

Looking up address using mapkit and searchbar

开发者 https://www.devze.com 2023-01-17 02:00 出处:网络
I am trying to make an app similar to the Maps of the iPhone. I want to use the Mapkit and a searchbar to look up an address.

I am trying to make an app similar to the Maps of the iPhone. I want to use the Mapkit and a searchbar to look up an address. And then use the address to add it to my tableview But I have actually no idea how to do this. Does someone have a clue for me? A tutorial or an example?

thanks in advance

======================

Right now I am able to search for the address with out a table. but I want to make it possible that when I press on a pin it will have a button on the annotation. I am using this code, but as you can see there is a NSLog, but it doesn't come up in my console:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    NSLog(@"This is called");
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"customloc"];
    [annView setPinColor:MKPinAnnotationColorPurple];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [button addTarget:self action:@selector(goDetail:) forControlEvents:UIControlEventTouchUpInside];

    annView.leftCalloutAccessoryView = button;
    annView.canShowCallout = YES;
    [annView setSelected:YES];
    [annView addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:nil];

    return annView;
}

also, when I open up my mapview. I get a pin on my current location, but for some reason my current location changes and a new pin was set on the map. I just want开发者_JAVA百科 the current location pin on it and one pin of my selected location can someone help me? this is my code:

-(void)addPins:(float)lat lon:(float)lon{

    CLLocationCoordinate2D location;
    location.latitude = lat;
    location.longitude = lon;

    // forcus around you
    MKCoordinateRegion region;
    region.center=location;
    MKCoordinateSpan span;
    span.latitudeDelta=0.005f; // this should be adjusted for high vs. low latitude - calc by cosign or sign
    span.longitudeDelta=0.005f;
    region.span=span;   
    [map setRegion:region animated:TRUE];   

    // add custom place mark
    CustomPlacemark *placemark=[[[CustomPlacemark alloc] initWithCoordinate:location] autorelease];
    placemark.title = @"";
    placemark.subtitle = @"";
    [map addAnnotation:placemark];
    [placemark release];
}


You must set a title and/or a subtitle for the custom MKAnnotation in order for it to be displayed.

0

精彩评论

暂无评论...
验证码 换一张
取 消