getting " Cannot read property 'type' of undefined" after my code returns?

2,024 views
Skip to first unread message

fearless_fool

unread,
Jan 30, 2012, 5:34:20 PM1/30/12
to google-map...@googlegroups.com
I'm getting the following error (show with stack trace) after my code completes:

  1. Uncaught TypeError: Cannot read property 'type' of undefined
    1. (anonymous function)
    2. Ve.mainmain.js:40
    3. (anonymous function)main.js:25
    4. Se.(anonymous function).kcmain.js:25
    5. Se.(anonymous function).kcmain.js:25
    6. Re.(anonymous function).Kdmain.js:24
    7. Se.(anonymous function).kcmain.js:25

Here's my js code (pretty straightforward):

$(function() {
    var loc = new google.maps.LatLng($('#map_canvas').attr('lat'), $('#map_canvas').attr('lng'));
    var maxZoomService = new google.maps.MaxZoomService();
    maxZoomService.getMaxZoomAtLatLng(loc, function(response) {
        // zoom to maxZoom - 1 if we can determine it, 14 otherwise
        var zoom = (response.status == google.maps.MaxZoomStatus.OK) ? (response.zoom - 1) : 14;
        var mapOptions = {
            center: loc,
            zoom: zoom,
            mapTypeId: google.maps.MapTypeId.SATELLITE};
        var myMap = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    });
});

What makes this difficult to debug is that the TypeError happens deep inside the google.maps.__gjsload__ code, long after my code has returned.  I can't figure out what state my code is creating that is causing the google library code to choke.

Any ideas, or suggestions on how to debug?

Barry Hunter

unread,
Jan 30, 2012, 5:41:07 PM1/30/12
to google-map...@googlegroups.com
Not sure how you attach the attributes, to #map_canvas, but are they numbers?

The API expects you to be sending numbers (not strings) when creating
a LatLng object.

try wrapping them in parseFloat.


If that guess doesnt help suggest supplying a link to your map.

> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-maps-js-api-v3/-/NDVqO_jXaDcJ.
> To post to this group, send email to google-map...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-maps-js-a...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.

fearless_fool

unread,
Jan 30, 2012, 7:25:35 PM1/30/12
to google-map...@googlegroups.com
@barryhunter:

Good suggestion, but it appears that I am passing floats (and not strings).  But I realized that I was loading the //maps/googleapis.com/maps script twice on the same page -- fixing that makes the problem -- er -- different.

Now I'm seeing the script work the first time and fail thereafter.  More specifically, the async callback to 

    maxZoomService.getMaxZoomAtLatLng()

gets called the first time the page is loaded.  But if I reload the page, the callback never happens (at least, it doesn't trigger a breakpoint in Chrome's debugger), and I get a 

Uncaught TypeError: Cannot read property 'value' of null

error from within

  %7Bcommon,util,controls,places_impl,maxzoom%7D.js:4

after my function returns.  Curiouser and curiouser.

Barry Hunter

unread,
Jan 31, 2012, 7:23:14 AM1/31/12
to google-map...@googlegroups.com
On Tue, Jan 31, 2012 at 12:25 AM, fearless_fool <rdp...@gmail.com> wrote:
>  But I realized that I was loading the //maps/googleapis.com/maps script
> twice on the same page

we have NO POSSIBLE WAY to know you did that. Unless you have another
thread, but its kind of rude to split a discussion without maintaining
a link between the threads.


That's pretty much why a link is always asked for.


(I suppose unless we find a way to hack into your computer, so we can
see your screen. But that is a bit OTT for a help forum)

Robert Poor

unread,
Jan 31, 2012, 12:11:17 PM1/31/12
to google-map...@googlegroups.com
Barry!

On Tue, Jan 31, 2012 at 04:23, Barry Hunter <barryb...@gmail.com> wrote:
> we have NO POSSIBLE WAY to know you did that. Unless you have another
> thread, but its kind of rude to split a discussion without maintaining
> a link between the threads.

Oy! Ouch. I intended no rudeness. I'd verified that I was passing
floats, as you'd suggested. Then I noticed that I was loading the
google scripts twice and thought that might make a difference --
loading the script once didn't make the problem go away, it just made
it different. So I reported on that.

> That's pretty much why a link is always asked for.

Agreed. It's a reasonable first step to say "I've observed problem X
-- has anyone else observed anything similar?" before posting a link.
Since we've gone that route, a link might be helpful. See below.

> (I suppose unless we find a way to hack into your computer, so we can
> see your screen. But that is a bit OTT for a help forum)

I'm honored that you're so invested in helping. A link is
problematic: if you're asking for a standalone / minimum case app,
that would take a LONG time to extract and test. The entire app is a
large Ruby on Rails project, being developed for a client and isn't
public. We could set you up with access to the app -- PM me if you
want to go this route.

Thanks!

- ff

Reply all
Reply to author
Forward
0 new messages