I am trying to create the map scale ruler on Google Map to show the scale ratio (1 cm to XXXX m ). The custom ruler should works like what Google map scale ruler is. When it comes to the testing, I have found that the number is always changing and increases linearly when zooming in or out. I know the Google map ruler does not want this happen to report fixed value until zoom level overflow happens. Could you please tell me how to enhance it ?
The below is my working
- (double ) mapViewRation :(GMSMapView*)mapView idleAtCameraPosition:(GMSCameraPosition*)position
{
CLLocationCoordinate2D topLeft = mapView.projection.visibleRegion.farLeft;
CLLocationCoordinate2D bottomLeft = mapView.projection.visibleRegion.nearLeft;
double lat = fabs(topLeft.latitude - bottomLeft.latitude);
double mpp = cos(lat * M_PI / 180) * 2 * M_PI * 6378137 / (256 * pow(2, mapView.camera.zoom));
double distance = mpp * mapView.frame.size.width;
return distance;
}
-(void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition*)position {
// handle you zoom related logic
NSLog(@"zoom : %f" , position.zoom );
double asK = [self mapViewRation : self.myMapView idleAtCameraPosition : position ];
double aasK= fmod(asK, 300);
UIView* lineView;
if(lineView==nil){
lineView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 400 , 1)];
lineView.backgroundColor = [UIColor blackColor];
}
CGRect make = CGRectMake(100, 200, 400-aasK , 1) ;
[lineView setFrame:make ];
UILabel* zeroLabel;
if(zeroLabel==nil){
zeroLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 400-aasK, 10)];
[zeroLabel setTextColor:[UIColor blackColor]];
[zeroLabel setBackgroundColor:[UIColor clearColor]];
[zeroLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 14.0f]];
}
[zeroLabel setText:[NSString stringWithFormat:@"%.1f" ,1.0f]];
UILabel* numberLabel;
if(numberLabel==nil){
numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(380-aasK, 10, 400-aasK, 10)];
[numberLabel setTextColor:[UIColor blackColor]];
[numberLabel setBackgroundColor:[UIColor clearColor]];
[numberLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 14.0f]];
}
CGRect maaake = CGRectMake(380-aasK, 10, 400-aasK , 10) ;
[numberLabel setFrame:maaake ];
[numberLabel setText:[NSString stringWithFormat:@"%f" ,position.zoom]];
[lineView addSubview:numberLabel];
[lineView addSubview:zeroLabel];
[self.view addSubview:lineView];
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire