Delegation for iphone-google-maps-component
The iphone-google-maps-component is a way for you to use Google Maps on the iPhone through the use of an extended UIWebView and an html file on a server somewhere that does the map loading.
The present code overrides the default delegate UIWebViewDelegate with its own, MapWebViewDelegate. You cannot use the setCenterWithLatLng to establish the starting location until the view has finished loading. With the override, the webViewDidFinishLoad delegate method is unavailable.
Going by this post, the following code changes will allow the use of both delegates.
MapWebView.h
1) Change protocol definition.@protocol MapWebViewDelegate < UIWebViewDelegate >
MapWebView.m
2) Remove the synthesize line.//@synthesize delegate;
3) Replace with own methods, to hook into super.delegate.- (id
return (id
}
- (void) setDelegate :(id
super.delegate = delegate;
}
webViewDidFinishLoad should be accessible, as well as the other methods in the UIWebViewDelegate.
Another way of setting the starting location is through the loadMap method in MapWebView.h. The URL string can accept two more variables, latitude and longitude.
Change this:NSString *urlStr = [NSString stringWithFormat:
@"http://www.wenear.com/iphone-test?width=%d&height=%d&zoom=%d",
width, height, DEFAULT_ZOOM_LEVEL];
To this:NSString *urlStr = [NSString stringWithFormat:
@"http://www.wenear.com/iphone-test?width=%d&height=%d&latitude=%f&longitude=%f&zoom=%d",
width, height, location.coordinate.latitude, location.coordinate.longitude, DEFAULT_ZOOM_LEVEL];
Here, location is a CLLocation, part of the CoreLocation framework. The loadMap method is publicly defined in the interface and it accepts location as its variable. The call in didMoveToSuperview should be properly handled.
The latitude and longitude are doubles and can be hardcoded instead.
1 comments:
And here is a tutorial for Google Maps made in paper :)
Pretty sure you'll like it.
http://www.youtube.com/watch?v=I9TtDecveCE
Post a Comment