0

I am getting location details from database as a json response and values are coming correctly but my problem is the alignment of content string getting error like unterminated string literal ...

then i am displaying this details in google map info window..

 var contentString = "<div><h4>Start Location : "+ locations[i].start_loc + "</h4>
                           <h4> Driver Name : "+ locations[i].driver_name + "</h4>
                           <h4> Driver Mob No : "+ locations[i].mob_num + "</h4>
                           <h4> Passenger Name : "+locations[i].passenger_name + "</h4>
                           <h4> Passenger Mob No : "+locations[i].mob_no + "</h4>
                           <h4> Cab Reg No : "+ locations[i].cab_reg_no + "</h4></div>"; 

                    infowindow.setContent(start_contentString);
                    infowindow.open(start_map, start_marker);

Please help me anyone....

2 Answers 2

2

Just add \ after every line:

var contentString = "<div><h4>Start Location : "+ test + "</h4> \
                           <h4> Driver Name : "+ locations[i].driver_name + "</h4> \
                           <h4> Driver Mob No : "+ locations[i].mob_num + "</h4> \
                           <h4> Passenger Name : "+locations[i].passenger_name + "</h4> \
                           <h4> Passenger Mob No : "+locations[i].mob_no + "</h4> \
                           <h4> Cab Reg No : "+ locations[i].cab_reg_no + "</h4></div>"; 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank You it's working now ...why escape ( \ ) added?? can you please explain
@mathi - it's used to escape the literal new line character. You could instead write every line like my answer below, added for reference only
0

Answer just to show alternative multiline...

var contentString = "<div><h4>Start Location : "+ test + "</h4>" + 
                       "<h4> Driver Name : "+ locations[i].driver_name + "</h4>" +
                       "<h4> Driver Mob No : "+ locations[i].mob_num + "</h4>" +
                       "<h4> Passenger Name : "+locations[i].passenger_name + "</h4>" +
                       "<h4> Passenger Mob No : "+locations[i].mob_no + "</h4>" +
                       "<h4> Cab Reg No : "+ locations[i].cab_reg_no + "</h4></div>"; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.