UIButtonでマップを拡大・縮小したいのですが、任意の位置で拡大・縮小ができません。表示している場所の緯度・経度を取得したいのですが、方法が分かりません。よろしくお願い致します
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答1件
0
ベストアンサー
lang
1import UIKit 2import MapKit 3 4class ViewController: UIViewController { 5 let mapView:MKMapView = MKMapView(frame: CGRectMake(0, 0, 300, 200)) 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup after loading the view, typically from a nib. 10 let co = CLLocationCoordinate2D(latitude: 35.68664111, longitude: 139.6948839) 11 var cr:MKCoordinateRegion = mapView.region 12 cr.center = co 13 cr.span.latitudeDelta = 0.5 14 cr.span.longitudeDelta = 0.5 15 16 mapView.setCenterCoordinate(co, animated: true) 17 mapView.setRegion(cr, animated: true) 18 self.view.addSubview(mapView) 19 20 let button = UIButton() 21 button.setTitle("zooom in !!", forState: .Normal) 22 button.setTitleColor(UIColor.blackColor(), forState: .Normal) 23 button.addTarget(self, action: "action", forControlEvents:.TouchUpInside) 24 button.sizeToFit() 25 button.center = self.view.center 26 self.view.addSubview(button) 27 } 28 29 func action(){ 30 var cr:MKCoordinateRegion = mapView.region 31 cr.span.latitudeDelta = 0.1 32 cr.span.longitudeDelta = 0.1 33 mapView.setRegion(cr, animated: true) 34 } 35 36 override func didReceiveMemoryWarning() { 37 super.didReceiveMemoryWarning() 38 // Dispose of any resources that can be recreated. 39 } 40 41 42} 43
UIButtonでマップを拡大・縮小したいのですが、任意の位置で拡大・縮小ができません。
上記コードのaction()にて、mapViewで現在表示中の位置を中心にズームしています。
UIbuttonから呼び出しています。
表示している場所の緯度・経度を取得したいのですが、方法が分かりません。よろしくお願い致します
lang
1 var cr:MKCoordinateRegion = mapView.region 2 cr.center.longitude 3 cr.center.latitude
で取得できます。
投稿2015/02/21 10:53
総合スコア231
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/02/21 12:25