Kapil
Posts: 0
Joined: Mon Feb 17, 2014 5:59 am

Setting Custom item on Google maps throwing : TypeError: Cannot read property 'offsetWidth' of undefined

I am trying to set custom icons on google maps. I I run it I get the error :

Uncaught TypeError: Cannot read property 'offsetWidth' of undefined

Here is my Javascript :

var map = Appery ('googlemap1');
var iconImage = 'https://maps.google.com/mapfiles/kml/...';
var myLatlng = new google.maps.LatLng(37.63, -122.424);

var mapOptions = {
zoom :17,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
alert('helloe');
alert('hello1');

var map = new google.maps.Map($('div[dsid="googlemap1"]').get(0), mapOptions);

var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Blabber Spot',
icon:iconImage
});
alert('hello2');

Kapil
Posts: 0
Joined: Mon Feb 17, 2014 5:59 am

Setting Custom item on Google maps throwing : TypeError: Cannot read property 'offsetWidth' of undefined

Here is the HTML from the source file. It is "googlemap1".

<!-- googlemap1 --

Code: Select all

                 [img]https://sslproxy.getsatisfaction.com/sslproxy/SWhAdDNLMG5zdGFuVGlWesDkulkDJFT8yaEQr7bYAleJlUj-NGFPfHUqA59NFzhaI_jF3qAffJTuzVj8kEH8Gr991JtJHbkSe6i_aPYpbe8opQlJ0ZmTaM0csIT6rMWuwBtR3cfH7BpnwB6QOs6MafCWOLT6eIEKFfcejLNUQNk=.png[/img]  

             ul name="googlemap1_markers" 
                 <!-- marker_8 -- 
                 li name="marker_8" 

                 /li 
             /ul
Kapil
Posts: 0
Joined: Mon Feb 17, 2014 5:59 am

Setting Custom item on Google maps throwing : TypeError: Cannot read property 'offsetWidth' of undefined

Attaching code from source file. It is googlemap1 Image

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Setting Custom item on Google maps throwing : TypeError: Cannot read property 'offsetWidth' of undefined

Hello,

Lets see if this help:

  • Put you code inside function
    pre
    code
    function gmap() {
    var map = Appery ('googlemap1');
    var iconImage = 'https:&#47;&#47;maps&#46;google&#46;com/mapfiles/kml/&#46;&#46;&#46;';
    var myLatlng = new google&#46;maps&#46;LatLng(37&#46;63, -122&#46;424);

    var mapOptions = {
    zoom :17,
    center: myLatlng,
    mapTypeId: google&#46;maps&#46;MapTypeId&#46;ROADMAP,
    };
    alert('helloe');
    alert('hello1');

    var map = new google&#46;maps&#46;Map($('div[dsid="googlemap1"]')&#46;get(0), mapOptions);

    var marker = new google&#46;maps&#46;Marker({
    position: myLatlng,
    map: map,
    title: 'Blabber Spot',
    icon:iconImage
    });
    alert('hello2');
    }
    /code
    /pre

    Invoke codegmap()/code function on "homePage" page load event.

Kapil
Posts: 0
Joined: Mon Feb 17, 2014 5:59 am

Setting Custom item on Google maps throwing : TypeError: Cannot read property 'offsetWidth' of undefined

This did the trick. Awesome!

Thank you so much.

Return to “Issues”