Adding KML to JavaScript app


I’m working to customize google maps within a JavaScript NativeScript app. I’ve installed the nativescript-google-maps-sdk plugin, and I can create a simple map and use the google map object to do other things, like add markers. What I need to do is add a kml layer. The Google Maps Android API docs show how, but their examples are in Java. The JavaScript docs I’ve found, have a JavaScript interface but do not show any methods to add layers such as kml.

This StackOverflow post suggests this might be possible, but I’m not understanding that example in the context of a NativeScript app. [Edit: upon closer examination, this one is Java too, not JavaScript.]

Does anyone have any suggestions? I’m not sure what more I can search on.


After sleeping on this, I think I’ll be better off using polylines rather than KML, I’ll just have to parse the data to get the coordinates. This has the advantage of eliminating the restriction where the KML files have to be available via http and cannot be packaged with the app (at least, on web-based mobile apps). I’ll post here later if this approach proves to be successful.


Yes, the nativescript-google-maps-sdk plugin appears to give me everything I need. I extracted the line coordinates from the .kml file and used that to create a poly line, and I used the point data to create markers. I’m actually more satisfied with this approach as it will be easier to automate, and eliminates the hassles with Google’s kml caching (which required a new URL every time a change was made to the kml file).