<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Eric Binnion</title> <atom:link href="http://ericbinnion.com/feed/" rel="self" type="application/rss+xml" /><link>http://ericbinnion.com</link> <description></description> <lastBuildDate>Tue, 07 Feb 2012 03:03:06 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Adding Custom Overlays to iOS MapKit Framework</title><link>http://ericbinnion.com/adding-custom-overlays-to-ios-mapkit-framework/</link> <comments>http://ericbinnion.com/adding-custom-overlays-to-ios-mapkit-framework/#comments</comments> <pubDate>Mon, 06 Feb 2012 20:26:53 +0000</pubDate> <dc:creator>Eric Binnion</dc:creator> <category><![CDATA[ios]]></category> <guid
isPermaLink="false">http://ericbinnion.com/?p=75</guid> <description><![CDATA[Series This is part 2 of a 2-part series on how to create customer overlays for the MapKit framework on iOS. View part 1 of this series here. Creating Custom Overlay in iOS Everything we have done up to this &#8230; <a
href="http://ericbinnion.com/adding-custom-overlays-to-ios-mapkit-framework/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<h3>Series</h3><p>This is part 2 of a 2-part series on how to create customer overlays for the MapKit framework on iOS. View part 1 of this series <a
title="Creating Custom Overlays for iOS MapKit Framework" href="http://ericbinnion.com/creating-custom-overlays-for-ios-mapkit-framework/">here</a>.</p><h3>Creating Custom Overlay in iOS</h3><p>Everything we have done up to this point has been to create the tiles we will use in our project. Now that we have created those tiles, we need to add them to our project.</p><p>For this, we will use a sample project from Apple called Tile Map. I have a working iOS project that uses custom overlay at <a
href="https://github.com/ebinnion/iMustangs-Map-Custom-Overlay" target="_blank">Github</a>. We are going to copy a few classes from this project, so go ahead and grab the zip-ball and open it in Xcode.</p><p>You will need to copy the following files into your own project:</p><ul><li>TileOverlay.h</li><li>TileOverlay.m</li><li>TileOverlayView.h</li><li>TileOVerlayView.m</li></ul><p
style="text-align: center;"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.39.49-PM.png" rel="lightbox[75]"><img
class="aligncenter" title="TileMap Project Screenshot" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.39.49-PM-300x192.png" alt="TileMap Project Screenshot" width="300" height="192" /></a></p><p>Be sure to select the box to &#8220;Copy items into destination group&#8217;s folder.&#8221; At this point I am going to assume that you have already created a View Controller for your map. If not, go ahead and create one. In the .m (implementation) file of your map View Controller, we are going to import the TileOverlay.h and TileOverlayView.h files. Your map View Controller should now look something like this:</p><p><span
id="more-75"></span></p><pre>#import "mapViewController.h"
#import "TileOverlay.h"
#import "TileOverlayView.h"
@implementation mapViewController
- (void)viewDidLoad
{
    NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Tiles"];
    TileOverlay *overlay = [[TileOverlay alloc] initWithTileDirectory:tileDirectory];
    [map addOverlay:overlay];
    map.mapType = MKMapTypeSatellite;
    MKCoordinateRegion CSC;
    // Defines the center point of the map
    CSC.center.latitude = 33.874809;
    CSC.center.longitude = -98.521129;
    // Defines the view,able area of the map. Lower numbers zoom in!
    CSC.span.latitudeDelta = .003;
    CSC.span.longitudeDelta = .003;
    [map setRegion:CSC animated:YES];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay
{
    TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:overlay];
    view.tileAlpha = 0.6;
    return [view autorelease];
}</pre><p>The only other change that we have to make at this point is to add some code to our app delegate file. In the delegate header file you will need to add some code (highlighted below):</p><pre>#import
@class mapViewController;
@interface msuAppDelegate : NSObject {
    UIWindow *window;
    mapViewController *viewController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) mapViewController *viewController;
@end</pre><p>We still don&#8217;t have tiles in our project at this point, so go ahead and create a directory on your Desktop named &#8220;Tiles&#8221;. Copy all of the tile sub-directories and the tilemapresource.xml into the &#8220;Tiles&#8221; folder that you created on the desktop. Now, drag the &#8220;Tiles&#8221; folder into your iOS project. Be sure to select &#8220;Copy items into destinations group&#8217;s folder&#8221; and &#8220;Create folder references for any added folders.&#8221;</p><div
id="attachment_81" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-6.08.55-PM-e1328573379892.png" rel="lightbox[75]"><img
class="size-medium wp-image-81" title="Copying Tiles folder into iOS Project" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-6.08.55-PM-300x187.png" alt="Copying Tiles folder into iOS Project" width="300" height="187" /></a><p
class="wp-caption-text">Copying Tiles folder into iOS Project</p></div><p>The last step is to connect your Mk Map View in storyboard to delegate. Once we do that, the Custom Overlay for MapKit should be working. Click the Mk Map View in storyboard, use control + click, then drag, to the Map View Controller Icon. View the screenshots below.</p><div
id="attachment_76" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-2.18.18-PM-e1328559602446.png" rel="lightbox[75]"><img
class="size-medium wp-image-76" title="Mk Map View Screenshot" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-2.18.18-PM-300x187.png" alt="Mk Map View Screenshot" width="300" height="187" /></a><p
class="wp-caption-text">Mk Map View Screenshot</p></div><div
id="attachment_77" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-2.18.24-PM-e1328559615977.png" rel="lightbox[75]"><img
class="size-medium wp-image-77" title="Connect Mk Map View Screenshot" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-2.18.24-PM-300x187.png" alt="Connect Mk Map View Screenshot" width="300" height="187" /></a><p
class="wp-caption-text">Connect Mk Map View Screenshot</p></div><div
id="attachment_78" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-2.18.26-PM-e1328559626810.png" rel="lightbox[75]"><img
class="size-medium wp-image-78" title="Map View Controller Delegate" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-06-at-2.18.26-PM-300x187.png" alt="Map View Controller Delegate" width="300" height="187" /></a><p
class="wp-caption-text">Map View Controller Delegate</p></div><p>At this point go ahead and run your program to see if everything is working. If you have any problems, please leave me a comment below, and I will modify this tutorial. You can reference the <a
href="https://github.com/ebinnion/MSU-iMustangs">iMustangs project  on Github</a> for an example of integrating custom overlays into an iOS project.</p> ]]></content:encoded> <wfw:commentRss>http://ericbinnion.com/adding-custom-overlays-to-ios-mapkit-framework/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Creating Custom Overlays for iOS MapKit Framework</title><link>http://ericbinnion.com/creating-custom-overlays-for-ios-mapkit-framework/</link> <comments>http://ericbinnion.com/creating-custom-overlays-for-ios-mapkit-framework/#comments</comments> <pubDate>Mon, 06 Feb 2012 05:49:46 +0000</pubDate> <dc:creator>Eric Binnion</dc:creator> <category><![CDATA[ios]]></category> <guid
isPermaLink="false">http://ericbinnion.com/?p=69</guid> <description><![CDATA[I am part of a team developing an iPhone app for Midwestern State University. I am particularly responsible for developing the map that we are going to use for the app. Because I had a lot of detail I wanted &#8230; <a
href="http://ericbinnion.com/creating-custom-overlays-for-ios-mapkit-framework/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>I am part of a team developing an iPhone app for Midwestern State University. I am particularly responsible for developing the map that we are going to use for the app. Because I had a lot of detail I wanted to show on our map &#8211; Faculty/Commuter/Resident Parking Lots,  labels for different buildings, key points of interest on campus &#8211; I began to look into using custom overlays, a large image laid of top of the Google map tiles.</p><p>One of the issues I ran into was a lack of good information on how to integrate custom overlays into an <strong>existing</strong> iOS project. What follows is the process used to create and integrate custom overlays into an existing iOS app.</p><h3>Create Overlay Image</h3><p>I knew from the beginning that I would need some graphic of Midwestern State University to serve as a foundation for me to build my overlay image. To get the background image, I:</p><ul><li>Went go Google Maps</li><li>Grabbed the embed code for the location I wanted</li><li>Created a quick HTML document with the embed code in it</li><li>I changed the size of the iframe to about 4,000 px by 4,000 px</li><li>I used a plugin for Google Chrome browser that took a screenshot of the <strong>entire</strong> page</li></ul><p>This gave me a background image that I could put into Photoshop and then build upon. I used 300 PPI and set my image size to about 3,000 px by 4,000 px. With a smaller image size or lower resolution I noticed that I had very jagged edges. You can tweak these image settings to your project.</p><p>Start building your overlay on top of this background image. When you have an overlay image that you are happy with, hide the background, and export your image. I exported my image as a PNG-24 since I had large amounts of blank area on the image.</p><h3>Find the Corner Coordinates</h3><p>The best way I found to match the corner pixels of the image to coordinates is to:<br
/> <span
id="more-69"></span></p><ul><li>Create a copy of your overlay image, this time with a red border</li><li>Add your overlay image to Google Earth<p><div
id="attachment_72" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.24.36-PM-e1328506220778.png" rel="lightbox[69]"><img
class="size-medium wp-image-72" title="Custom overlay with red border added" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.24.36-PM-300x187.png" alt="Custom overlay with red border added" width="300" height="187" /></a><p
class="wp-caption-text">Custom overlay with red border added</p></div></li><li>Stretch/move your image so that it lines up. Below is the result that I had.<p><div
id="attachment_71" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.25.04-PM-e1328506233237.png" rel="lightbox[69]"><img
class=" wp-image-71" title="Close up of overlay image" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.25.04-PM-300x187.png" alt="Close up of overlay image" width="300" height="187" /></a><p
class="wp-caption-text">Close up of overlay image</p></div></li><li>Drop a pin on each corner of your image. Be sure to zoom in as close as possible, and get the pin as close to the corner as possible<p><div
id="attachment_73" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.24.53-PM-e1328506205691.png" rel="lightbox[69]"><img
class="size-medium wp-image-73" title="Close up of pin" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-11.24.53-PM-300x187.png" alt="Close up of pin" width="300" height="187" /></a><p
class="wp-caption-text">Close up of pin</p></div></li><li>Right click on each pin in the left toolbar, and select &#8220;Directions from here&#8221;</li></ul><div>Selecting &#8220;directions from here&#8221; will put the coordinates for the pin in the search form. Copy these down.</div><h3>Create Custom Overlay Tiles</h3><p>MapKit, and Google Maps, works by using map tiles. These are square images that only load if they are viewable in the zoom level that you are looking at. Thankfully, there is a tool called GDAL that will take our overlay image and cut it up into all of the tiles that we need. Take a minute and go download and install GDAL. If you&#8217;re on a Mac, I would suggest using <a
href="http://www.kyngchaos.com/software/frameworks" target="_blank">Kyng Chaos</a>. I will be giving the Mac commands below, but I assume that they are similar on a PC.</p><p>Because we are referencing each corner pixel of our overlay image to a coordinate, we need to know how many pixels wide and tall our image is. To do this, we are going to use the gdalinfo command. Before we can use gdalinfo though, we need to get in the directory of our image/project. Go ahead and navigate to the directory of your project, then use the gdalinfo command followed by your image name. Your commands should look something similar to this:</p><pre>cd /Users/ericbinnion/Desktop/imgDirectory-Here
gdalinfo imgName.png</pre><p>This should give us some information that looks like the image below:</p><div
id="attachment_70" class="wp-caption aligncenter" style="width: 310px"><a
href="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-8.52.39-PM.png" rel="lightbox[69]"><img
class="size-medium wp-image-70" title="gdalinfo screenshot" src="http://ericbinnion.com/wp-content/uploads/2012/02/Screen-Shot-2012-02-05-at-8.52.39-PM-300x216.png" alt="gdalinfo screenshot" width="300" height="216" /></a><p
class="wp-caption-text">A screenshot of the gdalinfo command on Mac.</p></div><p>Next, we will create our VRT file which will reference the coordinates to the corner pixels. To do this, use the following command:</p><pre>gdal_translate -of VRT -a_srs EPSG:4326 -gcp 0 0 -98.526518119 33.8812011706 -gcp 1055 0 -98.5158112852 33.8811992984 -gcp 1055 1584 -98.5158116258 33.8679003639 -gcp 0 1584 -98.5265176807 33.8679047769  msuMap.png msuMap.vrt</pre><p>You will of course replace the coordinate points, the image name, and the vrt name that you want create to fit your project. The last step of the project is to actually create the tiles. To do this, we will use the following command.</p><pre>python gdal2tiles.py -z 14-21  msuMap.vrt</pre><p>This will create tiles for zoom levels 14-21 using the msuMap.vrt file that we created in the last step. At this point you should see some html files in your project. These will give you a preview of how your custom overlay will look on MapKit for iOS.</p><h3>Series</h3><p>This is part 1 of a 2-part series in &#8220;How to Create Custom Overlay Tiles for iOS MapKit Framework.&#8221; View part 2 <a
title="Adding Custom Overlays to iOS MapKit Framework" href="http://ericbinnion.com/adding-custom-overlays-to-ios-mapkit-framework/">here</a>.</p> ]]></content:encoded> <wfw:commentRss>http://ericbinnion.com/creating-custom-overlays-for-ios-mapkit-framework/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
