संपादित करें: मेरा मानना है कि मेरी समस्या यह है कि यह कोड पूर्णांक ज़ूम स्तरों के लिए काम करता है, लेकिन मैं इसे फ्लोट ज़ूम स्तरों के लिए काम करना चाहता हूं।एक मानचित्र के ज़ूम/सीमाओं के साथ मैपकिट मानचित्र के ज़ूम/सीमाओं से मेल करें
मेरे पास एक आईओएस ऐप है जिसमें उपयोगकर्ता रूटमे-आधारित मानचित्र और मैपकिट-आधारित मानचित्र के बीच स्विच कर सकता है।
जब वे स्रोत स्विच करते हैं, तो मैं एक ही क्षेत्र में एक जैसा सटीक दिखाना चाहता हूं। हालांकि, मैं यह नहीं समझ सकता कि उन्हें कैसे मिलान किया जाए क्योंकि रूटमे और मैपकिट नक्शा सीमाओं का वर्णन करने के लिए विभिन्न डेटा संरचनाओं का उपयोग करते हैं।
यहां कुछ कोड है जो इसे कुछ हद तक बंद कर देता है, लेकिन यह सटीक नहीं है। इस कोड को आता है से: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
मुझे यकीन है कि इस कोड को तय किया जाना चाहिए कि क्या, या संभवतः मैं एक बहुत आसान समाधान अनदेखी कर रहा हूँ नहीं हूँ। एप्पल के MapKit कोड अंतर्निहित Google नक्शे API जब आप फोन कर रहा है:
#define MERCATOR_OFFSET 268435456
#define MERCATOR_RADIUS 85445659.44705395
#pragma mark -
#pragma mark Map conversion methods
- (double)longitudeToPixelSpaceX:(double)longitude {
return round(MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * M_PI/180.0);
}
- (double)latitudeToPixelSpaceY:(double)latitude {
return round(MERCATOR_OFFSET - MERCATOR_RADIUS * logf((1 + sinf(latitude * M_PI/180.0))/(1 - sinf(latitude * M_PI/180.0)))/2.0);
}
- (double)pixelSpaceXToLongitude:(double)pixelX {
return ((round(pixelX) - MERCATOR_OFFSET)/MERCATOR_RADIUS) * 180.0/M_PI;
}
- (double)pixelSpaceYToLatitude:(double)pixelY {
return (M_PI/2.0 - 2.0 * atan(exp((round(pixelY) - MERCATOR_OFFSET)/MERCATOR_RADIUS))) * 180.0/M_PI;
}
- (MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mapView
centerCoordinate:(CLLocationCoordinate2D)centerCoordinate
andZoomLevel:(NSInteger)zoomLevel {
// convert center coordiate to pixel space
double centerPixelX = [self longitudeToPixelSpaceX:centerCoordinate.longitude];
double centerPixelY = [self latitudeToPixelSpaceY:centerCoordinate.latitude];
// determine the scale value from the zoom level
NSInteger zoomExponent = 20 - zoomLevel;
double zoomScale = pow(2, zoomExponent);
// scale the map’s size in pixel space
CGSize mapSizeInPixels = mapView.bounds.size;
double scaledMapWidth = mapSizeInPixels.width * zoomScale;
double scaledMapHeight = mapSizeInPixels.height * zoomScale;
// figure out the position of the top-left pixel
double topLeftPixelX = centerPixelX - (scaledMapWidth/2);
double topLeftPixelY = centerPixelY - (scaledMapHeight/2);
// find delta between left and right longitudes
CLLocationDegrees minLng = [self pixelSpaceXToLongitude:topLeftPixelX];
CLLocationDegrees maxLng = [self pixelSpaceXToLongitude:topLeftPixelX + scaledMapWidth];
CLLocationDegrees longitudeDelta = maxLng - minLng;
// find delta between top and bottom latitudes
CLLocationDegrees minLat = [self pixelSpaceYToLatitude:topLeftPixelY];
CLLocationDegrees maxLat = [self pixelSpaceYToLatitude:topLeftPixelY + scaledMapHeight];
CLLocationDegrees latitudeDelta = -1 * (maxLat - minLat);
// create and return the lat/lng span
MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta, longitudeDelta);
return span;
}
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate
zoomLevel:(NSUInteger)zoomLevel
animated:(BOOL)animated {
// use the zoom level to compute the region
MKCoordinateSpan span = [self coordinateSpanWithMapView:self
centerCoordinate:centerCoordinate
andZoomLevel:zoomLevel];
MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate, span);
// set the region like normal
[self setRegion:region animated:animated];
}
एमके मैपव्यू के बारे में मैंने जो कुछ देखा है, वह यह है कि यदि आप क्षेत्र को सेट करते हैं और फिर इसे तुरंत वापस पढ़ते हैं, तो आप अलग-अलग मान वापस लेते हैं। हमारे ऐप में, मैंने वह मान सेट किया जो एक प्रतिनिधि कॉलबैक को ट्रिगर करता है और फिर मैंने नया मान पढ़ा और इसका उपयोग यह निर्धारित करने के लिए किया कि हमारे ओवरले कहां रखना है। यकीन नहीं है कि यह मदद करता है। :-( – EricS