{"id":7928,"date":"2013-10-08T10:22:24","date_gmt":"2013-10-08T14:22:24","guid":{"rendered":"http:\/\/blog.xamarin.com\/?p=7928"},"modified":"2013-10-08T10:22:24","modified_gmt":"2013-10-08T14:22:24","slug":"map-snapshots","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/map-snapshots\/","title":{"rendered":"Map Snapshots"},"content":{"rendered":"<p dir=\"ltr\">Continuing the snapshotting topic from <a href=\"\/snapshotting-views-in-ios-7\/\" target=\"_blank\">my earlier post<\/a>, this post looks at the snapshotting capability included in MapKit.<\/p>\n<p dir=\"ltr\">To take a map snapshot in iOS 7, you can use the new MKMapSnapshotter class. This class takes snapshots asynchronously, always returning the best possible map image. For example, if you request a snapshot of a map before the tiles have loaded, MKMapSnapshotter will create the snapshot image when the tiles are available.<\/p>\n<p dir=\"ltr\">Taking a snapshot is easy. You simply create an MKMapSnapshotOptions instance, pass it to an MKMapSnapshotter, and call the MKMapSnapshotter&#8217;s Start method. When the snapshot is complete, you can get the image from the Image property of the MKMapSnapshot instance that is passed to the MKMapSnapshotCompletionHandler.<\/p>\n<p dir=\"ltr\">For example, the following code sets up map options to take a snapshot of a 500m region around the map&#8217;s center:<\/p>\n<pre class=\"lang:csharp decode:true\">\nvar coord = new CLLocationCoordinate2D(42.346751, -71.096946);\nvar region = MKCoordinateRegion.FromDistance (coord, 500, 500);\nmap.SetCenterCoordinate (coord, false);\n\nsnapshot.TouchUpInside += (sender, e) =&gt; {\n  var options = new MKMapSnapshotOptions {\n      Size = mapImageView.Bounds.Size,\n      Region = region,\n      MapType = MKMapType.Hydrid\n  };\n\n  var snapper = new MKMapSnapshotter (options);\n\n  snapper.Start ((snap, err) =&gt; {\n      if (err == null) {\n          mapImageView.Image = snap.Image;\n      }\n  });\n};\n<\/pre>\n<p dir=\"ltr\">This results in the image snapshot shown below:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/lh4.googleusercontent.com\/3Vwihkrx3Ewft-eQZEPP146XeumrS1nW7587rFuIwzJxXRGoJLvGTO8GTaz-JPwtpZOSjTVx4OZcWjCGpSNhfHtKnY3XasXcXJAlQWC1I_zd1noR0FjlGw7y\" width=\"166px;\" height=\"334px;\" \/><\/p>\n<p dir=\"ltr\">As you can see, the snapshot does not need to match the map exactly. You can snapshot a portion of the map, as well as alter other aspects of the map snapshot from the original map, such as the size. You can even have the snapshot be a different map type than the displayed map. In fact, you don&#8217;t even need to have a displayed map, as the\u00a0MKMapSnapshotter instance is completely independent of any MKMapView you may have in the application.<\/p>\n<p dir=\"ltr\">For example, setting the MapType to MKMapType.Standard in the MKMapSnapshotOptions results in a standard map snapshot, while the map itself remains a hybrid type:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/lh6.googleusercontent.com\/A_5cv-Leohe91UTkBVDwlwrh1b_E_K1nxmmuRLo_VZVYn7n8qnOwCwM9CChi9r9BR-QWFSPS5U7x49DDAULdX3Z4hFnYflLLsUc3zBiNUHkTLcyDH73Q9YSN\" width=\"166px;\" height=\"334px;\" \/><\/p>\n<p dir=\"ltr\">The code from this post is available <a href=\"https:\/\/github.com\/mikebluestein\/MapSnapshotDemo\" target=\"_blank\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Continuing the snapshotting topic from my earlier post, this post looks at the snapshotting capability included in MapKit. To take a map snapshot in iOS 7, you can use the new MKMapSnapshotter class. This class takes snapshots asynchronously, always returning the best possible map image. For example, if you request a snapshot of a map [&hellip;]<\/p>\n","protected":false},"author":1932,"featured_media":39167,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4],"class_list":["post-7928","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>Continuing the snapshotting topic from my earlier post, this post looks at the snapshotting capability included in MapKit. To take a map snapshot in iOS 7, you can use the new MKMapSnapshotter class. This class takes snapshots asynchronously, always returning the best possible map image. For example, if you request a snapshot of a map [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/7928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/1932"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=7928"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/7928\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/39167"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=7928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=7928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=7928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}