使用 Mapkit 和搜索栏查找地址
我正在尝试制作一个类似于 iPhone 地图的应用程序。 我想使用 Mapkit 和搜索栏来查找地址。 然后使用该地址将其添加到我的表视图中 但我实际上不知道该怎么做。 有人有线索给我吗? 教程还是例子?
提前致谢
======================
现在我可以在没有表格的情况下搜索地址。 但我想让当我按下图钉时,注释上会有一个按钮。 我正在使用这段代码,但正如你所看到的,有一个 NSLog,但它没有出现在我的控制台中:
- (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;
}
另外,当我打开我的地图视图时。我获得了当前位置的图钉,但由于某种原因,我当前的位置发生了变化,并且在地图上设置了新的图钉。 我只想要当前位置图钉和我所选位置的图钉 有人可以帮助我吗? 这是我的代码:
-(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];
}
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 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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须为自定义 MKAnnotation 设置标题和/或副标题才能显示它。
You must set a title and/or a subtitle for the custom MKAnnotation in order for it to be displayed.