troubleshooting Question

Need help calling a Perl Script from a Google Maps JavaScript

Avatar of jimtwest3
jimtwest3Flag for United States of America asked on
JavaScriptPerlWeb DevelopmentHTMLGoogle
59 Comments1 Solution237 ViewsLast Modified:
Currently my Google Maps Javascript has a Mouse Click Event defined:

// Configure the click listener.
map.addListener('click', function(mapsMouseEvent) {
// Create a new InfoWindow.
  infoWindow = new google.maps.InfoWindow({position: mapsMouseEvent.latLng});
  infoWindow.setContent(mapsMouseEvent.latLng.toString());
  infoWindow.open(map);
});

I need to call a Perl Script and pass the latitude and longitude of the Mouse Click to the Perl script from my Google Maps Javascript..

The Perl script will calculate the distance and bearing from the last mouse click to the current mouse click.  

Here is an example of calling the Perl script from a Linux command line:

]# perl BRData.pl -16.7097  -150.9753
-16.7097  -150.9753  Distance: 0.0 nm

# perl BRData.pl -16.1037 -150.2667                                                                
-16.1037  -150.2667  Distance: 55 nm, Bearing: 48

The first call to BRData.pl stores the mouse click latitude and longitude.

The second call to BRData.pl calculates the Distance and Bearing from the first mouse position to the current mouse position.

In Google Maps, I think, but am not sure, the latitude and longitude are "e.latlng.lat" and "e.latlng.lng".  I

 need to call the Perl Script "BRData.pl" and pass "e.latlng.lat" and "e.latlng.lng", and capture the Perl script stdout output line, "  -16.1037  -150.2667  Distance: 55 nm, Bearing: 48".

I then would like to print the stdout output line in the Google Maps "infowindow" popup.  

I have not been able to successfully call the Perl Script  BRData.pl  from my Google Maps Javascript.  

I tried using the "exec" function in nodejs, but that is not working:

// Configure the click listener.
map.addListener('click', function(mapsMouseEvent) {
 
// Create a new InfoWindow.
  infoWindow = new google.maps.InfoWindow({position: mapsMouseEvent.latLng});
 
const { exec } = require("child_process").exec;
exec("perl /var/www/cgi-bin/skipper/BRData.pl mapsMouseEvent.latLng.toString()");
 
//    infoWindow.setContent(mapsMouseEvent.latLng.toString());
    infoWindow.setContent($(stdout));
 
  infoWindow.open(map);
});

My nodejs rpm installation is:

nodejs-child-process-close-0.1.1-2.el6.noarch
nodejs-0.10.48-3.el6.x86_64

I would really appreciate some help on calling my BRData.pl from my Mouse Click Event in my Google Maps javascript.

For a Perl script to call the BRData.pl script, this could be done in a single line:

$text = `perl $dir/BRData.pl  $lat2 $long2`;

Basically I need the Javascript equivalent of that single Perl line calling the Perl script BRData.pl, and capturing the STDOUT generated by the Perl Script..    

Maybe the lat and long for the mouse click is not "e.latlng.lat" and "e.latlng.long" ??  
Maybe my call to  the nodejs function "exec" has a mistake.  
Maybe the output of "exec" is not "STDOUT". is not "$(stdout).  .

It appears from my debugging that my Perl Script BRData.pl is never being call from my Google Maps Javascript.

I would really appreciate some help with this problem.  

Thanks,
Jim West
 





ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 1 Answer and 59 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 59 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros