0

Hey I have following code which gives me an error: "Uncaught SyntaxError: Unexpected token :"

My code:

    $.getJSON("http://maps.googleapis.com/maps/api/place/details/json?reference="+ref_tel+"&sensor=true&key=MY_API_KEY&callback=?",
       function(data){

}, "json");

What's wrong?

P.S. the JSON looks like below:

    {
  "html_attributions" : [],
  "result" : {
    "address_components" : [
      {
        "long_name" : "48",
        "short_name" : "48",
        "types" : [ "street_number" ]
      },
      {
        "long_name" : "Pirrama Road",
        "short_name" : "Pirrama Road",
        "types" : [ "route" ]
      },
      {
        "long_name" : "Pyrmont",
        "short_name" : "Pyrmont",
        "types" : [ "locality", "political" ]
      },
      {
        "long_name" : "NSW",
        "short_name" : "NSW",
        "types" : [ "administrative_area_level_1", "political" ]
      },
      {
        "long_name" : "AU",
        "short_name" : "AU",
        "types" : [ "country", "political" ]
      },
      {
        "long_name" : "2009",
        "short_name" : "2009",
        "types" : [ "postal_code" ]
      }
    ],
    "formatted_address" : "5/48 Pirrama Road, Pyrmont NSW, Australia",
    "formatted_phone_number" : "(02) 9374 4000",
    "geometry" : {
      "location" : {
        "lat" : -33.8669710,
        "lng" : 151.1958750
      }
    },
    "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
    "id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7",
    "international_phone_number" : "+61 2 9374 4000",
    "name" : "Google Sydney",
    "rating" : 4.60,
    "reference" : "CnRlAAAAAfV6JIqSzL8Cf4VnXn0EaI1d5k3IPhdkEonq0MxiUbQFFSVuptVbXbNH4mrevb0bc7G8yWqTUv76i4KTuO_Wf3OrRHjCJJwzQ0mNLjbYGSVqy2eqyrgOUkl6S_sJfTbHzWZYrfPy7KZaet0mM5S6thIQJYuy5v_JD--ZxXEJLWTQRRoU5UaciXBBo89K-bce18Ii9RsEIws",
    "types" : [ "store", "establishment" ],
    "url" : "http://maps.google.com/maps/place?cid=10281119596374313554",
    "vicinity" : "5/48 Pirrama Road, Pyrmont",
    "website" : "http://www.google.com.au/"
  },
  "status" : "OK"
}

And debugger shows Me that the error is on line 2. Can someone fix this?

4
  • This is not a great way to ask a question. Do you have any more information about the error? A line number maybe? Did you have it working before you made some change? It might be the ? at the end of your URL? Commented Feb 18, 2012 at 10:18
  • The ? is used by jquery to append a callback function name for the JSONP request. Commented Feb 18, 2012 at 10:20
  • can you see the response in the firebug or fiddler or chrome developer tools Commented Feb 18, 2012 at 10:41
  • Here U are, the response looks like I show, and debugger shows an error on line 2: "html_attributions" : [], Commented Feb 18, 2012 at 10:42

1 Answer 1

1

Google Maps Places API doesn't seem to support JSONP. Thus you are not able to use it at the client-side (Also you will expose your API key if put it somewhere in the source code).

By the way, your code throws an error because of

{
  "something" : value
}

is interpreted as block of code (a statement) instead of an object (an expression). Javascript has labels with the following syntax:

labelName : statement

But only identifier may be used as a label name. String (or, more generally, any expression) can not. This results in a syntax error.

Sign up to request clarification or add additional context in comments.

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.