2016-01-20 54 views
1

我在地图上有一个滑块,我试图通过滑块进行放大。下面是我使用的代码,当+或 - 被击中的地图只显示蓝色(水)使用滑块缩放WKInterfaceMap(WKInterfaceSlider)

- (IBAction)sliderAction:(float)value { 
     RestaurantObject *restaurant = [nearbyMapArray objectAtIndex:0]; 
     CLLocationCoordinate2D mapLocation = CLLocationCoordinate2DMake([restaurant.latitude doubleValue]*value, [restaurant.longitude doubleValue]*value); 
     MKCoordinateSpan coordinateSpan = MKCoordinateSpanMake(1, 1); 
     [self.map setRegion:(MKCoordinateRegionMake(mapLocation, coordinateSpan))]; 
    } 

回答

0

你可能通过经纬度值在错误的地方。 试试这个,应该可以工作

- (IBAction)sliderAction:(UISlider*)slider 
{ 
    CGFloat value = slider.value; // slider.maximumValue - slider.value // if you want reverse effect 
    CGFloat sliderMax = slider.maximumValue; 
    CGFloat zoom = value/sliderMax; 
    RestaurantObject *restaurant = [nearbyMapArray objectAtIndex:0]; 
    CLLocationCoordinate2D mapLocation = CLLocationCoordinate2DMake([restaurant.latitude doubleValue], [restaurant.longitude doubleValue]); 
    MKCoordinateSpan coordinateSpan = MKCoordinateSpanMake(1*zoom, 1*zoom); 
    [self.map setRegion:(MKCoordinateRegionMake(mapLocation, coordinateSpan))]; 
}