1

I want to plot multiple markers on my Google Map. I am creating a JavaFX desktop app which includes having a map with multiple markers plotted on it. The problem I'm getting is how do I send Strings from Java to JavaScript? The Strings are longitudes and latitudes of multiple addresses.

My first solution was to create a Json file that was held locally however this is not an effective solution as this app will be used on multiple machines so using a local file wouldn't work. Now I am trying to use WebEngines executeScript but I'm not 100% on how I would take these strings and put them into javascript for google maps by using this method.

This is my Java code:

private void latLong(List<ResponseInfo> latLongs) {

    for (ResponseInfo latlong : latLongs) {

    WebEngine webEngine = new WebEngine();
     webEngine.executeScript("" +
        "window.lat = " + latlong.getLatitude() + ";" +
        "window.lon = " +      latlong.getLongitude() + ";" +
           "document.markLocations(window.lat, window.lon);");

    }
}

This is my JS code:

function initialize() {
var center = new google.maps.LatLng(51.524077, -0.079357);
var mapOptions = {
    zoom : 14,
    center : center,
    mapTypeId : google.maps.MapTypeId.ROAD,
    mapTypeControl : false,
    streetViewControl : false,
    fullscreenControl : false,
    clickableIcons : false,
    styles : mapStyle
};

 var map = new google.maps.Map(document.getElementById('map'), mapOptions);
}

document.markLocations = function(x, y) {
var latLng = new google.maps.LatLng(x, y);
var marker = new google.maps.Marker({
    position : latLng,
    icon : icons[feature.type].icon,
    map : map
});

}

What I expect is multiple markers, which can vary from 1 to 1000, to display on the map. Currently what I have tried shows me this error 'Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: TypeError: document.markLocations is not a function.'

Daniel
  • 29
  • 1
  • 5
  • 1
    Possible duplicate of [How can I use the Google Maps APIs in a JavaFX Desktop Application?](https://stackoverflow.com/questions/37647933/how-can-i-use-the-google-maps-apis-in-a-javafx-desktop-application) – Randy Casburn Jun 04 '19 at 14:02

0 Answers0