私はmapviewアプリケーションをやっています。私はアドレスを持つ一連の連絡先を持っています。これを使用して座標に変換します
-(CLLocationCoordinate2D) getLocationFromAddressString:(NSString*) addressStr {
NSString *urlStr = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[addressStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr] encoding:NSStringEncodingConversionAllowLossy error:nil];
NSArray *items = [locationStr componentsSeparatedByString:@","];
double latitude = 0.0;
double longitude = 0.0;
if([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[items objectAtIndex:2] doubleValue];
longitude = [[items objectAtIndex:3] doubleValue];
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
マップビューは、最適なズーム形式でロードする必要があります。マップ上のすべてのピンが一度にユーザーに表示され、ユーザーはズームインおよびズームアウトできる必要があります。以前の IOS バージョンでこの問題を解決する方法を見つけました。IOS6 で問題に直面しています。助けが必要。
編集:これはズームに使用したコードです
for(MKPointAnnotation* annotation in annotationArray)
{
topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}
MKCoordinateRegion region;
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1;
region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1;
region = [mapViews regionThatFits:region];
[mapView setRegion:region animated:NO];
私が直面している問題は、途中でいくつかの矛盾があり、マップがズームすることを意図した地域にズームすることです。
編集: 問題は、住所がイギリスの連絡先と日本の住所の別の連絡先がある場合、マップビューで両方のピンを同時に表示できないことです。イングランドと日本を含むエリア全体の正確な中心となるエリアにズームインします。つまり、どちらのピンもマップビューに表示されません。2 つのピンを表示するには、どちらかの側にスライドする必要があります。これは、マップビューの最大ズーム レベルと関係があります。