6

マップの焦点を合わせたい緯度と経度の座標があります。それらはNSStringとして保存され、以下の場所に変換されます。

NSString *placeLatitude = [elementCoords objectForKey:@"placeLatitude"];
NSString *placeLongitude = [elementCoords objectForKey:@"placeLongitude"];

CLLocationCoordinate2D location;
location.latitude = [placeLatitude doubleValue];
location.longitude = [placeLongitude doubleValue];

ユーザーの現在の場所ではなく、上記で指定した緯度と経度に焦点を合わせるように、以下を変更するにはどうすればよいですか?

MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.05;
mapRegion.span.longitudeDelta = 0.05;
4

5 に答える 5

8
    MKCoordinateRegion region;
   CLLocation *locObj = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake([placeLatitude doubleValue], [placeLongitude doubleValue])
                                                   altitude:0
                                         horizontalAccuracy:0
                                           verticalAccuracy:0
                                                  timestamp:[NSDate date]];
    region.center = locObj.coordinate;  
    MKCoordinateSpan span; 
    span.latitudeDelta  = 1; // values for zoom
    span.longitudeDelta = 1; 
    region.span = span;
    [self.mapView setRegion:region animated:YES];
于 2013-03-07T07:11:58.420 に答える
6

setCenterCoordinate:animated:マップのフォーカスポイントを移動するために使用します。ビューを読み込んでいて、すぐに正しい位置に設定したい場合は、を設定animated:NOします。そうでない場合は、マップをスムーズに中央に配置するようにパンしたい場合は、をlocation設定します。animated:YES

[mapView setCenterCoordinate:location animated:YES];

もちろん、これによってマップビューのズームレベルが変わることはありません。ズームレベルを更新する場合は、を使用する必要がありますsetRegion:animated:。たとえば、2倍近くにズームインする場合:

// Halve the width and height in the zoom level.
// If you want a constant zoom level, just set .longitude/latitudeDelta to the
// constant amount you would like.
// Note: a constant longitude/latitude != constant distance depending on distance
//       from poles or equator.
MKCoordinateSpan span =
    { .longitudeDelta = mapView.region.span.longitudeDelta / 2,
      .latitudeDelta  = mapView.region.span.latitudeDelta  / 2 };

// Create a new MKMapRegion with the new span, using the center we want.
MKCoordinateRegion region = { .center = location, .span = span };
[mapView setRegion:region animated:YES];
于 2013-03-07T07:22:47.973 に答える
1

SWIFT3に更新

let span = MKCoordinateSpan(latitudeDelta: mapView.region.span.latitudeDelta / 2, longitudeDelta: mapView.region.span.latitudeDelta  / 2)

        // Create a new MKMapRegion with the new span, using the center we want.
        let region = MKCoordinateRegion(center: location, span: span)

        mapView.setRegion(region, animated: true)
于 2016-09-27T14:34:06.320 に答える
0

ユーザーの現在の場所をmapRegionセンターとして設定しないでください。座標を地図の中心位置として設定する必要があります

于 2013-03-07T07:04:43.863 に答える
0
CLLocationCoordinate2D location;
location.latitude =  [[[matchingItems objectAtIndex:j] valueForKey:@"latitude"] doubleValue];
location.longitude = [[[matchingItems objectAtIndex:j] valueForKey:@"longitude"] doubleValue];

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance (location, 2000, 2000);
[mywebView setRegion:region animated:YES];
于 2014-09-18T06:51:42.280 に答える