Fix: can not load KML file from on ionic 3
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.4.2-beta-20180831-1408" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.4.2-beta-20180901-2335" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="Promise" src="www/Promise.js">
<runs/>

MODIFY
src/android/plugin/google/maps/AsyncLoadImage.java
src/android/plugin/google/maps/AsyncLoadImage.java
@@ -189,12 +189,15 @@ public class AsyncLoadImage extends AsyncTask<Void, Void, AsyncLoadImage.AsyncLo
//--------------------------------
if (!iconUrl.startsWith("data:image")) {
- if ((currentPageUrl.startsWith("http://localhost") ||
- currentPageUrl.startsWith("http://127.0.0.1")) &&
- !iconUrl.contains("://")) {
+ if (currentPageUrl.startsWith("http://localhost") ||
+ currentPageUrl.startsWith("http://127.0.0.1")) {
+ if (iconUrl.contains("://")) {
+ iconUrl = iconUrl.replaceAll("http://.+?/", "file:///android_asset/www/");
+ } else {
// Avoid WebViewLocalServer (because can not make a connection for some reason)
iconUrl = "file:///android_asset/www/".concat(iconUrl);
}
+ }
if (!iconUrl.contains("://") &&
!iconUrl.startsWith("/") &&

MODIFY
src/android/plugin/google/maps/PluginKmlOverlay.java
src/android/plugin/google/maps/PluginKmlOverlay.java
package plugin.google.maps;
import android.os.Bundle;
-import android.util.Log;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
@@ -76,6 +75,18 @@ public class PluginKmlOverlay extends MyPlugin implements MyPluginInterface {
!urlStr.startsWith("../")) {
urlStr = "./" + urlStr;
}
+
+ if (currentPageUrl.startsWith("http://localhost") ||
+ currentPageUrl.startsWith("http://127.0.0.1")) {
+ if (urlStr.contains("://")) {
+ urlStr = urlStr.replaceAll("http://.+?/", "file:///android_asset/www/");
+ } else {
+ // Avoid WebViewLocalServer (because can not make a connection for some reason)
+ urlStr = "file:///android_asset/www/".concat(urlStr);
+ }
+ }
+
+
if (urlStr.startsWith("./") || urlStr.startsWith("../")) {
urlStr = urlStr.replace("././", "./");
currentPageUrl = currentPageUrl.replaceAll("[^\\/]*$", "");

MODIFY
src/android/plugin/google/maps/PluginTileProvider.java
src/android/plugin/google/maps/PluginTileProvider.java
@@ -174,6 +174,16 @@ public class PluginTileProvider implements TileProvider {
}
}
+ if (urlStr.startsWith("http://localhost") ||
+ urlStr.startsWith("http://127.0.0.1")) {
+ if (urlStr.contains("://")) {
+ urlStr = urlStr.replaceAll("http://.+?/", "file:///android_asset/www/");
+ } else {
+ // Avoid WebViewLocalServer (because can not make a connection for some reason)
+ urlStr = "file:///android_asset/www/".concat(urlStr);
+ }
+ }
+
try {
InputStream inputStream = null;
if (urlStr.startsWith("http://") || urlStr.startsWith("https://")) {

MODIFY
www/KmlOverlay.js
www/KmlOverlay.js
@@ -131,7 +131,7 @@ var KmlOverlay = function(map, kmlId, camera, kmlData, kmlOverlayOptions) {
name.style.fontWeight = 500;
name.style.fontSize = "medium";
name.style.marginBottom = 0;
- name.innerText = overlay.get('name') || "";
+ name.innerText = overlay.get('name').value || "";
result.appendChild(name);
}
if (overlay.get('snippet')) {

Fix: can not load KML file from http://localhost on ionic 3 #2410