I want to show multiple number of markers on goolemaps which is of different colours say red, green ,orange ,black marker shown in the below image.I have to show the price in the marker when I select some marker then Marker image must change same like the below image
I am getting lat and long of marker from web services and using that data I am add markers,text in the marker using the below code but the Image is becoming blur .
-(void)hourelywebsevice:(NSString *)withlogintoken withlat:(double )weblat withlong:(double )weblong withcoustamerid:(NSString *)coustamerid{
NSLog(@"%@",withlogintoken);
NSLog(@"%f",weblat);
NSString *weblatstring=[NSString stringWithFormat:@"%f",weblat];
NSString *weblongstring=[NSString stringWithFormat:@"%f",weblong];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:weblatstring,@"lat",weblongstring,@"lon",coustamerid,@"customer_id",hourlyWebFromDateStr,@"fromtime",hourlyWebToDateStr,@"totime",withlogintoken,@"login_token",filtervechtypestr,@"vehicle_type",filteraminitesarray,@"amenities",filtertypearray,@"type", nil];
NSLog(@"%@",dict);
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
[manager POST:@"http://park24x7.com/betav2/apipoint/gethourlyserviceproviders" parameters:dict progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"%@", responseObject);
userarray=[responseObject objectForKey:@"data"];
statusstring=[NSString stringWithFormat:@"%@", [responseObject objectForKey:@"status"]];
NSInteger number=1;
NSInteger statustwonumber=2;
integerAsString = [NSString stringWithFormat:@"%ld",(long)number];
useridstring1=[NSString stringWithFormat:@"%@", [userarray valueForKey:@"id"]];
NSString *satustwostring= [NSString stringWithFormat:@"%ld",(long)number];
alertstring =[responseObject objectForKey:@"message"];
if([statusstring isEqualToString:integerAsString])
{
NSLog(@"%@",alertstring);
//
if (!(alertstring.length==0 )) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:alertstring
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[activityIndicatorView stopAnimating];
[alert show];
}else{
vehicle_id=[NSString stringWithFormat:@"%@", [responseObject objectForKey:@"vehicle_id"]];
Carnumber_string=[NSString stringWithFormat:@"%@", [responseObject objectForKey:@"vehicle_number"]];
int i;
for (i=0; i<userarray.count; i++)
{
marker1 = [[GMSMarker alloc] init];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,60,60)];
NSString *space_remaingcountstring=[[userarray objectAtIndex:i ]valueForKey:@"space_remain"];
NSInteger space_remaingcountInt=[space_remaingcountstring integerValue];
UIImageView *pinImageView;
int spacesAvilable,spacesOccupied,spacesRemain;
NSString *spacesAvilableStr,*spacesOccupiedStr,*spacesRemainStr;
spacesAvilableStr=[[userarray objectAtIndex:i ]valueForKey:@"space_available"];
;
spacesOccupiedStr=[[userarray objectAtIndex:i ]valueForKey:@"space_occupied"];
spacesRemainStr=[[userarray objectAtIndex:i ]valueForKey:@"space_remain"];
spacesAvilable=[spacesAvilableStr intValue];
spacesOccupied=[spacesOccupiedStr intValue];
spacesRemain=[spacesRemainStr intValue];
float precentage = 100*spacesOccupied/spacesAvilable;
NSLog(@" precentage %f",precentage);
if (spacesAvilable<=2) {
pinImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"marker-orange-48"]];
}
else
{
if (precentage<=50) {
pinImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"marker-green-48"]];
}else if (precentage>50)
{
pinImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"marker-black-48"]];
}
}
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(12, 7, 30, 20)];
NSString *pricestring=[[userarray objectAtIndex:i ]valueForKey:@"hourly_price"];
label.text=pricestring;
label.textColor=[UIColor colorWithRed:187/255.0 green:0/255.0 blue:29/255.0 alpha:1];
label.font=[UIFont systemFontOfSize:9.0f];
[view addSubview:pinImageView];
[pinImageView addSubview:label];
UIImage *markerIcon = [self imageFromView:view];
marker1.icon = markerIcon;
NSString *resultdictlatstring=[[userarray objectAtIndex:i ]valueForKey:@"loc_lat"];
float resultdictlatfloat=[resultdictlatstring floatValue];
NSLog(@"%f",resultdictlatfloat);
NSString *resultdictlongstring=[[userarray objectAtIndex:i ]valueForKey:@"loc_long"];
float resultdictlongfloat=[resultdictlongstring floatValue];
NSLog(@"%f",resultdictlongfloat);
marker1.position = CLLocationCoordinate2DMake(resultdictlatfloat, resultdictlongfloat);
NSLog(@"%f",marker1.position);
marker1.appearAnimation = kGMSMarkerAnimationPop;
marker1.map = hrlymapView;
marker1.zIndex=i;
NSLog(@"%d",marker1.zIndex);
}
[activityView stopAnimating];
}
}
else if ([statusstring isEqualToString:satustwostring]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:alertstring
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[activityIndicatorView stopAnimating];
[alert show];
[activityView stopAnimating];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:alertstring
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[activityIndicatorView stopAnimating];
[alert show];
[hrlymapView clear];
[activityView stopAnimating];
}
}
failure:^(NSURLSessionTask* operation, NSError* error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!!"
message:@"The Internet connection appears to be offline"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[activityIndicatorView stopAnimating];
[alert show];
[activityView stopAnimating];
[hrlymapView clear];
NSLog(@"Error: %@", error);
}];
}
- (UIImage *)imageFromView:(UIView *) view
{
UIGraphicsBeginImageContext(view.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
// if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
// UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]);
// } else {
// UIGraphicsBeginImageContext(view.frame.size);
// }
// [view.layer renderInContext: UIGraphicsGetCurrentContext()];
// UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
// return image;
}
In didtap marker I am add belowcode to get the data from the marker I change the image of marker but I it not working
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)tappedMarker
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
_hourlyparkingSpotDetailsView.hidden=NO;
_hourlyTapOnMarkerLblView.hidden=YES;
_monthlyParkingSpotDetailsView.hidden=NO;
_currentLocationBtn.frame=CGRectMake(_currentLocationBtn.frame.origin.x, _hourlyparkingSpotDetailsView.frame.origin.y-80, _currentLocationBtn.frame.size.width, _currentLocationBtn.frame.size.height);
//marker.map=nil;
NSLog(@"You tapped at %f,%f", tappedMarker.position.latitude,tappedMarker.position.longitude);
destinationlat_fvalue=tappedMarker.position.latitude;
destinationlon_fvalue=tappedMarker.position.longitude;
tappedMarker.icon=[UIImage imageNamed:@"pin-selected"];
NSLog(@"%d",tappedMarker.zIndex);
_hourlyparkingSpotDetailsView.hidden=NO;
_hourlyTapOnMarkerLblView.hidden=YES;
_monthlyParkingSpotDetailsView.hidden=YES;
_hourlyparkingSpotAddressLbl.text=[[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"address"];
_hourlyParkingSpotPriceLbl.text=[NSString stringWithFormat:@"%@/h",[[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"hourly_price"]];
_markerSpaceIdStr=[[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"space_id"];
_hourlyParkingSpotZoneId=[[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"zone_id"];
_hourlyParkingSptVehicleType=[[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"vehicle_type"];
_hourlyreviews=[NSString stringWithFormat:@"%@ Reviews", [[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"reviws"]] ;
_hourlyspacetype=[[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"space_type"];
NSString *currency_symbol=[NSString stringWithFormat:@"%@", [[userarray objectAtIndex:tappedMarker.zIndex ]valueForKey:@"currency_symbol"]];
_hourlyRupeeSymbolLbl.text=currency_symbol;
[defaults setObject:currency_symbol forKey:@"currency_symbol"];
_hourlyAutomatedLbl.text=_hourlyspacetype;
_hourlyReviewsLbl.text=_hourlyreviews;
if(isMarkerActive == TRUE){
[self unhighlightMarker:marker1];
}
isMarkerActive = TRUE;
selectedMarker = tappedMarker;
[self highlightMarker:tappedMarker];
return YES;
}
-(void)highlightMarker:(GMSMarker *)tappedMarker{
if([hrlymapView.selectedMarker isEqual:tappedMarker]){
tappedMarker.icon = [UIImage imageNamed:@"pin-selected"];
}
}
-(void)unhighlightMarker:(GMSMarker* )UntappedMarker{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,70)];
UIImageView *pinImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin-red-2"]];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(23, 15, 29, 23)];
NSString *pricestring=[[userarray objectAtIndex:UntappedMarker.zIndex ]valueForKey:@"hourly_price"];
label.text=pricestring;
label.textColor=[UIColor colorWithRed:187/255.0 green:0/255.0 blue:29/255.0 alpha:1];
label.font=[UIFont systemFontOfSize:11.0f];
[view addSubview:pinImageView];
[pinImageView addSubview:label];
UIImage *markerIcon = [self imageFromView:view];
UntappedMarker.icon = markerIcon;
}
Thanks for quick answer,If you have any doubts in the code please let me know.