मुझे निम्न समस्या है:आईओएस - मैप व्यू को किसी विशिष्ट क्षेत्र में कैसे सीमित करें?
मेरे पास एक "खींचा नक्शा" (छवि) है जिसे मैं MapView में ओवरले के रूप में जोड़ता हूं। इसके साथ कोई समस्या नहीं है .. लेकिन मुझे ओवरव्यू के क्षेत्र में MapView को सीमित करने की आवश्यकता है, इसलिए कोई उपयोगकर्ता इस क्षेत्र के बाहर स्क्रॉल/ज़ूम करने में सक्षम नहीं है .. लेकिन "सीमाओं के अंदर स्क्रॉल/ज़ूम करना संभव होना चाहिए "ओवरले का मतलब है - इसका मतलब है कि मैं MapView के लिए बस ज़ूम/स्क्रॉलिंग अक्षम नहीं कर सकता।
क्या इस विषय पर कोई विचार/समाधान है? MapView/-Kit का उपयोग करने का कारण यह है कि मुझे कस्टम मानचित्र में विभिन्न पीओआई जोड़ने की आवश्यकता है। कस्टम मानचित्र पेश करने के लिए केवल एक छवि दृश्य + स्क्रॉलव्यू का उपयोग करते समय यह अधिक जटिल हो सकता है।
मैंने इस विषय पर बहुत कुछ शोध किया है, लेकिन मुझे कोई अच्छा समाधान नहीं मिला।
किसी भी मदद की सराहना की जाती है!
शुभकामनाओं सहित, ईसाई
संपादित करें: आप की आपूर्ति एक topleft और एक bottomright नक्शा सीमित करने के लिए समन्वय: यह हमारी समाधान है। (न्यूनतम) ज़ूमलेवल भी सीमित है। मैंने गति को निष्क्रिय कर दिया है और आप मानचित्र के थोड़ा सा बाउंस करने में सक्षम हैं (बेहतर प्रदर्शन/ux के लिए)। मैंने ओवरले में ~ 1 किमी ग्रे ग्रे सीमा जोड़ा ताकि उपयोगकर्ता Google के ऑरगनल वर्ल्डमैप को देखने में सक्षम न हो।
LimitedMapView.h:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface LimitedMapView : MKMapView <UIScrollViewDelegate>{
}
@property (nonatomic, assign) CLLocationCoordinate2D topLeftCoordinate;
@property (nonatomic, assign) CLLocationCoordinate2D bottomRightCoordinate;
@end
LimitedMapView.m:
#import "LimitedMapView.h"
@implementation LimitedMapView
@synthesize topLeftCoordinate, bottomRightCoordinate;
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
if([super respondsToSelector:@selector(scrollViewDidZoom:)]) [super scrollViewDidZoom:scrollView];
if ([self region].span.latitudeDelta > 0.002401f || [self region].span.longitudeDelta > 0.003433f) {
CLLocationCoordinate2D center = self.centerCoordinate;
MKCoordinateSpan span = MKCoordinateSpanMake(0.002401f, 0.003433f);
self.region = MKCoordinateRegionMake(center, span);
}
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if([super respondsToSelector:@selector(scrollViewDidEndDragging:)]) [super scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
MKCoordinateRegion currentRegion = self.region;
bool changeRegionLong = YES;
bool changeRegionLat = YES;
// LONGITUDE
if((currentRegion.center.longitude - (currentRegion.span.longitudeDelta/2)) < self.topLeftCoordinate.longitude) {
currentRegion.center.longitude = (topLeftCoordinate.longitude + (currentRegion.span.longitudeDelta/2));
} else if((currentRegion.center.longitude + (currentRegion.span.longitudeDelta/2)) > self.bottomRightCoordinate.longitude) {
currentRegion.center.longitude = (bottomRightCoordinate.longitude - (currentRegion.span.longitudeDelta/2));
} else {
changeRegionLong = NO;
}
// LATITUDE
if((currentRegion.center.latitude + (currentRegion.span.latitudeDelta/2)) > self.topLeftCoordinate.latitude) {
currentRegion.center.latitude = (topLeftCoordinate.latitude - (currentRegion.span.latitudeDelta/2));
} else if((currentRegion.center.latitude - (currentRegion.span.latitudeDelta/2)) < self.bottomRightCoordinate.latitude) {
currentRegion.center.latitude = (bottomRightCoordinate.latitude + (currentRegion.span.latitudeDelta/2));
} else {
changeRegionLat = NO;
}
if(changeRegionLong || changeRegionLat) [self setRegion:currentRegion animated:YES];
}
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
[scrollView setContentOffset:scrollView.contentOffset animated:YES];
}
@end
मेरी समाधान जोड़ा। – cweinberger
समाधान के साथ अद्यतन करने के लिए धन्यवाद। मैं बस अधिकतम ज़ूम को सीमित करना चाहता था, और केवल एक स्क्रॉल का उपयोग कर एक समस्या में भाग गया/दृश्यव्यूडिज़ ज़ूम: किसी और के लिए, सुनिश्चित करें कि आप अपनी नई अवधि को चेक अवधि के मुकाबले कम से कम सेट करें अन्यथा मैपव्यू अधिकतम पर फंस जाएगा ज़ूम। – Andrew
स्विफ्ट के लिए एक बेहतर लिखित समाधान है http://stackoverflow.com/a/31799617/2814964 – cl3m