2016-01-20 78 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))]; 
}