0

in iOS 9, i use a wkwebview to render a google map, i want to listen to google map zoom level using the following code:

google.maps.event.addListener(gMap, 'zoom_changed', function() {
                                            var zoomLevel = gMap.getZoom();
                                            level = zoomLevel;
                                            alert(level);
                                            });

i do implement WKWEBVIEW delegate and set it to the web view . the alert never shows.

Ty Lertwichaiworawit
  • 2,950
  • 2
  • 23
  • 42
dennis
  • 117
  • 2
  • 10
  • by the way this is working in uiwebview ,but uiwebview has memory problems ,so after iOS8, i use wkwebview – dennis Oct 19 '15 at 06:35

1 Answers1

0

finally ,i solved the problem , in the local html ,i write:`

        <script type="text/javascript" src="map.js"></script>`

when add the code in the question to map.js when init ,it doesn't work.

i manage to get it work by add the following code in object c:

    NSString *tripscriptstr = [[NSBundle mainBundle]pathForResource:@"tripscript" ofType:@"txt"];
NSString *source =  [NSString stringWithContentsOfFile:tripscriptstr encoding:NSUTF8StringEncoding error:nil];

WKUserScript *script = [[WKUserScript alloc]initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];

[configuration.userContentController addUserScript:script];

int the txt file ,is the code in the question

dennis
  • 117
  • 2
  • 10
  • in ios9 url filewithurl not working, so i solved it by create temp directory like http://stackoverflow.com/questions/24882834/wkwebview-not-loading-local-files-under-ios-8 i did not update js file after change it in temporary directory – dennis Oct 19 '15 at 08:22