Reputation: 1168
I have multiple locations on Google map that work fine. I display the title for each location in a bubble. The problem is when I insert apostrophe into the title" ' ". Then it stops working. I have tried to replace the apostrophe " ' " with '. This fixes the problem but also display the ' in the title. My current code is:
function initialize(){
geocoder = new google.maps.Geocoder();
var locations = [
<cfoutput query="qryOutletPostcodes">
<cfhttp url="http://maps.googleapis.com/maps/api/geocode/json?address=#postcode#&sensor=false" result="myResult">
<cfset cfData=DeserializeJSON(myResult.filecontent)>
<cfset lat= #cfData.results[1].geometry.location.lat# >
<cfset lng= #cfData.results[1].geometry.location.lng# >
/* [ '<a href="outlets/###id#">#title#</a>', #lat#,#lng#],
[ '<a href="outlets/###id#">#htmlEditFormat(replace(title, "'", "'", "all"))#</a>', #lat#,#lng#], */
[ '<a href="outlets/###id#">#htmlEditFormat(replace(title, "'", "'", "all"))#</a>', #lat#,#lng#],
</cfoutput>
];
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 7,
center: new google.maps.LatLng( 51.508742, -0.107346),
mapTypeId: google.maps.MapTypeId.ROADMAP,
});
Is there a way to fix this problem? Any help would be appreciated.
Upvotes: 0
Views: 279
Reputation: 2723
Try doing:
replace("'", "\'")
You simply need to escape the apostrophe within the string.
Edit Sorry didn't read the comments and notice it was answered. Will leave this in place for future Googlers.
Upvotes: 1