1

I am implementing google map api for my website, but smarty is throwing some kind of syntax error in the javascript module. This is really surprising because I just copied the code from examples given on google's website.

Smarty Says:

on line 236 "var myLatLng = {lat: -25.363, lng: 131.044};" - Unexpected ": ", expected one of: "}"

and my Javascript tag is:

 function initMap() {
   var myLatLng = {lat: -25.363, lng: 131.044};

   var map = new google.maps.Map(document.getElementById('map'), {
     zoom: 4,
     center: myLatLng
   });

   var marker = new google.maps.Marker({
     position: myLatLng,
     map: map,
     title: 'Hello World!'
   });
 }

I don't understand what the problem is and how to solve this.

2 Answers 2

1

Try setting position as a new google.maps.LatLng([lat], [lng]) object.

function initMap() {
   var myLatLng = new google.maps.LatLng('-25.363', '131.044');

   var map = new google.maps.Map(document.getElementById('map'), {
     zoom: 4,
     center: myLatLng
   });

   var marker = new google.maps.Marker({
     position: myLatLng,
     map: map,
     title: 'Hello World!'
   });
 }
Sign up to request clarification or add additional context in comments.

3 Comments

Although my answer worked out for you, it didn't help to know the source of your problem. So, i think that this answer can help you with the smarty error you're getting.
Yeah exactly. I didnt get to know the root cause of the problem myself. Have to go through with the documentation of smarty for that.
I have posted a link for an answer that might help you with that on my previous comment. stackoverflow.com/questions/5429012/… <- this one.
1

Changing

var myLatLng = {lat: -25.363, lng: 131.044};

to,

var myLatLng = new google.maps.LatLng('-25.363', '131.044');

actually worked.

Thanks to the person who posted the answer at first but then deleted it somehow.

1 Comment

I hadn't seen that the question had to do with smarty. So i thought my answer wouldn't help at all. I've undeleted it.

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.