Jump to content

Trim Characters: Not a Function?


Spunky

Recommended Posts

saveLatLng = results[0].geometry.location;chop = saveLatLng.slice(1, -1);alert(chop);

With the above code, I get an error for the second line: Uncaught TypeError: undefined is not a function

saveLatLng = results[0].geometry.location;chop = saveLatLng.substr(1);alert(chop);

With this code I get same type of error. Why??? I'm just trying to trim off the first and last character (I realize the above code with their current parameters won't succeed but right now I'm trying to see what exactly the snippet will do). Right now saveLatLng is something like this: (43.049586, -88.04959684). I don't want the parentheses around it, so I'm just trying to shave it.

Link to comment
Share on other sites

Which line does the error appear on?

 

Are you certain that saveLatLng is a string and not something else?

 

Ok so I used toString() to make it a string first if it wasn't and the code works, thank you again. :good:

 

Shine some light for me first though..

var address = document.getElementById('address').value;  geocoder.geocode( { 'address': address}, function(results, status) {    if (status == google.maps.GeocoderStatus.OK) {      map.setCenter(results[0].geometry.location);      var marker = new google.maps.Marker({          map: map,          position: results[0].geometry.location,      });	  	  saveLatLng = results[0].geometry.location;

This is the code where the variable originates. The user input is text. saveLatLng is numbers. Is it then an integer by default? Therefore making it not a string?

Link to comment
Share on other sites

No, saveLatLng is probably an array with two values in it: one for latitude and one for longitude. In which case, you don't need to manipulate it.

 

Open your browser's developer tools, then use console.log(saveLatLng) to see what it really is.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...