I am getting driving distance from google map api v3 using this code.
distance11 = response.routes[0].legs[0].distance.text;
The code is working fine, but the output is coming in the format 300km. I need only the number 300. Please help me find a solution.
I already tried putting distance.value and simply distance but it didn’t work.
Edit:…..
Also please tell me how to remove string from a variable using javascript. For instance getting only 300 from 300km.
Thanks!
For this particular case, you can try
parseIntautomatically removes the trailing string after the number. But if you know already thatdistance11ends with"km", you can also do