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 ) delegate {
return (id )super.delegate;
}
- (void) setDelegate :(id ) delegate {
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.
No comments:
Post a Comment