Skip to content

Instantly share code, notes, and snippets.

@jfahrenkrug
Created February 2, 2010 15:40
Show Gist options
  • Save jfahrenkrug/292748 to your computer and use it in GitHub Desktop.
Save jfahrenkrug/292748 to your computer and use it in GitHub Desktop.
@import <Foundation/CPObject.j>
@import <MapKit/MKMapView.j>
@import <MapKit/MKMarker.j>
@import <MapKit/MKLocation.j>
@implementation AppController : CPObject
{
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
@outlet CPTextField nameTextField;
@outlet CPView customView;
MKMapView mapView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
}
- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.
// In this case, we want the window from Cib to become our full browser window
//[theWindow setFullBridge:YES];
mapView = [[MKMapView alloc] initWithFrame:[customView frame] apiKey:""];
[mapView setFrameOrigin:CGPointMake(0.0, 0.0)];
[mapView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
[customView addSubview:mapView];
}
- (@action)sayHi:(id)sender
{
alert("Hello " + [nameTextField stringValue]);
}
- (@action)setLocation:(id)sender
{
var gm = [MKMapView gmNamespace];
var geocoder = new gm.ClientGeocoder();
var address = [sender stringValue];
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " could not be found.");
} else {
[self moveMapToLocation:point];
}
}
);
}
- (void)moveMapToLocation:(id)aLatLng {
var loc = [[MKLocation alloc] initWithLatLng:aLatLng];
var marker = [[MKMarker alloc] initAtLocation:loc];
[mapView setCenter:loc];
[marker setDraggable:NO];
[marker addToMapView:mapView];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment