How to write a java script code in a html page by a java program at run time?

59 views Asked by At

I am using google maps java script API, and I want to shows some points on the map whose latitudes and longitudes I have in my java program. So basically I want to write this code in my java script at run time-

    var flightPlanCoordinates = [
      { lat: 21.124180, lng: 79.050505},
      {lat: 21.124435, lng: 79.049764},
      {lat: 21.124435, lng: 79.049764},
    ];  // these points will  decided at run time in my java program

So how do I pass this information from java program to my java script file?

1

There are 1 answers

0
Nikolay Baranenko On

for example in JSP You have

<c:set var="json_text">
[
      { lat: 21.124180, lng: 79.050505},
      {lat: 21.124435, lng: 79.049764},
      {lat: 21.124435, lng: 79.049764},
    ]
</c:set>

try to use in JavaScript

           var jsonObj = ${json_text};
    do {
console.log(jsonObj[a].lat+"; "+jsonObj[a].lng);
                a += 1;
            } while (a < jsonObj.length)