GMapsFX icon indicating copy to clipboard operation
GMapsFX copied to clipboard

"ReferenceError: Can't find variable: google" when I try to use GeocodingService

Open bmarsaud opened this issue 6 years ago • 2 comments

I'm trying to use GeocodingService in controller that's not displaying a map, so, that not implements MapComponentInitializedListener. I'm getting this error when I instantiate à new GeocodingService :

Caused by: netscape.javascript.JSException: ReferenceError: Can't find variable: google
	at javafx.web/com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:157)
	at javafx.web/com.sun.webkit.WebPage.twkExecuteScript(Native Method)
	at javafx.web/com.sun.webkit.WebPage.executeScript(WebPage.java:1509)
	at javafx.web/javafx.scene.web.WebEngine.executeScript(WebEngine.java:973)
	at com.lynden.gmapsfx.javascript.JavaFxWebEngine.executeScript(JavaFxWebEngine.java:42)
	at com.lynden.gmapsfx.javascript.JavascriptRuntime.execute(JavascriptRuntime.java:63)
	at com.lynden.gmapsfx.javascript.JavascriptObject.<init>(JavascriptObject.java:76)
	at com.lynden.gmapsfx.javascript.JavascriptObject.<init>(JavascriptObject.java:50)
	at com.lynden.gmapsfx.service.geocoding.GeocodingService.<init>(GeocodingService.java:36)
	at fr.lip.bmarsaud.dcenvfootprint.controller.DataCenterSettingsController.initialize(DataCenterSettingsController.java:46)

I have another loaded scene, where the map is displayed and the geocoding is working fine here.

bmarsaud avatar May 02 '18 14:05 bmarsaud

What version of java are you using?

I'm having the same issue with jre 1.8.0_181 but it goes away when I use jre 1.8.0_77, so I'm guessing something broke/changed in a recent version of java. Haven't narrowed it down beyond that yet.

ethanmdavidson avatar Jul 25 '18 16:07 ethanmdavidson

Okay, so for some reason it is unable to load the google's script loader which loads the maps api. The workaround is simply to load the maps api directly by modifying src/main/resources/com/lynden/gmapsfx/html/maps.html as follows:

<!--<script src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script>-->
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<!--<script type="text/javascript" src="https://www.google.com/jsapi"></script>-->
<script language='javascript'>

	function loadMapLibrary(ver, key, lang, region) {
		//alert('loadMapLibrary');
		var opts = [];
		if (key !== 'null') {
			opts[opts.length] = 'key='+key;
		}
		if (lang !== 'null') {
			opts[opts.length] = 'language='+lang;
		}
		if (region !== 'null') {
			opts[opts.length] = 'region='+region;
		}
		var sOpts = opts.join('&');
		
		if (ver === 'null') {
			ver = '3.exp';
		}
		
		//google.load('maps', ver, { 'other_params' : sOpts, 'callback': 'initMap()' });
		initMap();
	}

This is making me reconsider my initial guess that it was the java updates, because other people have also reported issues with google's script loader. However, when I open the url (https://www.google.com/jsapi) in my browser, it loads quickly enough. Perhaps it's a java security thing, where it won't load the external script?

ethanmdavidson avatar Jul 25 '18 20:07 ethanmdavidson