0

I'm having a problem dealing with Struts 2 and Javascript. This is the javascript code:

geocoder.geocode({'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    var latitud = results[0].geometry.location.lat();
                    var longitud = results[0].geometry.location.lng();
                    document.getElementById("goPlans_evo_latitud").value = latitud;
                    document.getElementById("goPlans_evo_longitud").value = longitud;
                    document.getElementById("goPlans").submit();
                } 
            });

When I'm trying to print these two values (latitude & longitude) on the script side it returns this (p.ex.):

41.3970035 2.189719200000013

And if I print them on the action method (after struts 2 set those values on Double objects) it returns this:

4.13970035E8 2.189719200000013E15

I noticed that this a scientific notation. I could try to format them but these values are wrong formatted.

This the action method (very simple):

public String goPlans() {
    System.out.println(evo.getLatitud() + " " + evo.getLongitud());
    return SUCCESS;
}

Can someone help me to know how set correctly these values using Struts 2?

Thank you.

EDIT: I found the problem! I need to declare the longitude and latitude bean variables as double (primitive) not as Double (Class).

frikkio
  • 93
  • 2
  • 10
  • possible duplicate of [How do I display whole number in JavaScript?](http://stackoverflow.com/questions/22129753/how-do-i-display-whole-number-in-javascript) or [How to avoid scientific notation for large numbers in javascript?](http://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript) – Xotic750 Mar 10 '14 at 12:59
  • The problem isn't in the Javascript side I think. It's on the action method side. – frikkio Mar 10 '14 at 13:03
  • What if you `console.log(latitud)` and/or `console.log(longitud)`? – Xotic750 Mar 10 '14 at 13:06
  • Show the code where did you print them, then you'll probably get answered. – Roman C Mar 10 '14 at 13:06
  • http://stackoverflow.com/a/13363576/1654265 – Andrea Ligios Mar 10 '14 at 13:18
  • But if you see, on the System.out, it prints a wrong number (4.13970035E8 is not 41.3970035) – frikkio Mar 10 '14 at 14:03
  • 1
    If you've found answer to your question then post it in the answer section. – Aleksandr M Mar 10 '14 at 17:25

1 Answers1

0

I found the problem! I need to declare the longitude and latitude bean variables as double (primitive) not as Double (Class).

frikkio
  • 93
  • 2
  • 10