Q. What is the simplest way to create link to Google Map with javascript?
A. Google Map has default url like: http://map.google.com/map?q=your address with sign "+" between words.
For example: address=1234 Some Ave, Somecity, ST 18999.
You need to convert that string to 1234+Some Ave+Somecity+ST+18999.
Simple way: address.replace(/,/g," ").replace(/ /g,"+").
First replace(/,/g," ") will be replaced all(golbal) "," to " ".
Second replace(/ /g,"+") will be replaced all " " to "+".
Final result will be like this: 'http://map.google.com/map?q=1234+Some+ Ave+Somecity+ST+18999'.
No comments:
Post a Comment