Google Maps API: Cannot set property ‘position’ of undefined

Cannot set property ‘position’ of undefined

If the Google Maps API v3 is returning this error here’s how to fix it.

Problem

I’ve used jQuery to get the map container but then it starts returning an error.

Solution

Try using the following code to get the map container:

Tags:

3 Responses to “Google Maps API: Cannot set property ‘position’ of undefined”

  1. kiki March 31, 2017 at 12:05 am #

    Hi Rick,
    Thanks for nice article.

    I’ve tried your code to fix my error. My codes below:

    If I use $(“.container”).find(“#map-canvas”)[0]; the result is undefined. Caused it I remove the index [0] from my code. But I am still getting error:

    Have you ideas about that?

    • Rick March 31, 2017 at 9:11 am #

      Four years after I wrote this, I honestly have no idea. The structure needed for the API might have changed.

      Have you tried copying one of the tutorials in the official documentation?

      https://developers.google.com/maps/documentation/javascript/

      • kiki April 1, 2017 at 11:08 pm #

        Yup, I already finding the same case with me and I’ll double check again.
        Thanks for advise.

Leave a Reply to Rick Click here to cancel reply.

Add <code> Some Code </code> by using this tags.