Show hotels (and near by places) by appropriate icon on Map in iPhone App
-
05-12-2019 - |
Question
I am using Google places API for getting places near by the predefined location.
It works fine. I am supposed to show PushPins for each place. For now, I am using default red pushpins for each place.
Now, I want to show appropriate icon for each place, for eg; for Hotels, Restaurants, etc....
On android, my colleague developers do the same thing, by using the Google API response.
In iPhone, I am not able to find any such help. Is there any way to do that on iPhone ???
Solution
This might not address your question. But, some work-around.
I have came across the similar problem. I did categorized the data, and showed notations according to that, along with the condition. Hope this code gives you some idea about how i did it.
-(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;
}
Best of luck...