在iPhone应用程序的地图上显示酒店(并靠近地方)在地图上的相应图标
问题描述:
我正在使用Google地方API获取预定位置附近的地点。在iPhone应用程序的地图上显示酒店(并靠近地方)在地图上的相应图标
它工作正常。我应该为每个地方显示PushPins。现在,我为每个地方使用默认的红色图钉。
现在,我想为每个地方显示适当的图标,例如: 适用于酒店,餐厅等......
在android上,我的同事开发者通过使用Google API响应来做同样的事情。
在iPhone中,我无法找到任何此类帮助。有没有办法在iPhone上做到这一点?
答
这可能不会解决您的问题。但是,一些解决方法。
我遇到过类似的问题。 我没有对数据进行分类,并根据这些数据和条件显示了符号。 希望这段代码能让你了解我是如何做到的。
-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *view = nil;
if (annotation != mapView.userLocation) {
view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
if (!view) {
view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];
CustomClassAnnotation *desclosureButton = [[CustomClassAnnotation alloc] initWithFrame:CGRectMake(0, 0, 29, 31)];
[desclosureButton addTarget:self action:@selector(mapAction:) forControlEvents:(UIControlEventTouchUpInside)];
view.rightCalloutAccessoryView = desclosureButton;
view.canShowCallout = YES;
}
((CustomClassAnnotation *)view.rightCalloutAccessoryView).annotation = annotation;
if (((MapViewAnnotation *)annotation).type == 1) {
view.image = [UIImage imageNamed:@"image_type1.png"];
}
else if (((MapViewAnnotation *)annotation).type == 2) {
view.image = [UIImage imageNamed:@"image_type2.png"];
}
else if (((MapViewAnnotation *)annotation).type == 3) {
view.image = [UIImage imageNamed:@"image_type3.png"];
}
}
return view;
}
祝你好运......
此外,通过此解决,图标自带的回应谷歌Places API的,是不能直接使用,因为你可以在代码中看到。 – Krishna 2012-02-06 17:01:02