Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Can't get google maps markers to show up

Featured Replies

I have 2 markers with the same coordinates, so i'm trying to approximate their coordinates so that they both display. I have the following code, that does not seem to work. Strange thing is that into the browser console i do not even see any error. Nothing, but no marker displays at all.

for (var i = 0; i < locations.length; i++) {
    var item = locations[i];
    var a = 0.01;
    var newLat = item[1] + -.00004 * Math.cos((+a*i) / 180 * Math.PI);  // x
    var newLng = item[2] + -.00004 * Math.sin((+a*i) / 180 * Math.PI);  // Y
    var finalLatLng = new google.maps.LatLng(newLat,newLng);

    var marker = new google.maps.Marker({
        position: finalLatLng,
        map: map,
        title: item[0],
        link: item[3],
        address: item[5],
        phone: item[6],
        mobile: item[7],
        website: item[8],
        image: item[9],
        readmore: item[10],
        icon: item[11],
        type: item[12],
        infoWindowIndex: i
    });

    marker.category = locations[i][12];
    gmarkers.push(marker);

    google.maps.event.addListener(marker, 'click', function (event) {

        var ua = navigator.userAgent;
        var event = (ua.match(/iPad/i)) ? "touchstart" : "click";

        // prevent ghost clicks on ipad
        infoBox.setContent('<div class="marker-wrapper animated fadeInDown"><div class="marker-title"> <a href="'+ this.link +'">'+ this.title +'</a> </div><div class="marker-content"><div class="two_third popup-content"><ul>'+ this.address +''+ this.phone +''+ this.mobile +''+ this.website +'</ul></div>'+ this.image +''+ this.readmore +'<div class="clearboth"></div> <div class="close" onClick=\'javascript:infoBox.close();\'><span class="icon-cancel"></span></div></div><span class="icon-down-dir"></span></div>');

        infoBox.open(map, this);
        map.setCenter(this.position);
        map.panTo(this.position);


    }); // end click even
} //end for

I have also tried editing the code this way by passing a new var to the position parameter and i get the errorUncaught InvalidValueError: setPosition: not a LatLng or LatLngLiteral: not an Object

Any clue how to fix this issue? Spent the whole morning trying but i haven't found a solution :(

for (var i = 0; i < locations.length; i++) {
    var item = locations[i];

    var myLatLng = new google.maps.LatLng(item[1], item[2] );

    var marker = new google.maps.Marker({
        position: myLatLng + (Math.random() -.5) / 1500,
        map: map,
        title: item[0],
        link: item[3],
        address: item[5],
        phone: item[6],
        mobile: item[7],
        website: item[8],
        image: item[9],
        readmore: item[10],
        icon: item[11],
        type: item[12],
        infoWindowIndex: i
    });

    marker.category = locations[i][12];
    gmarkers.push(marker);

    google.maps.event.addListener(marker, 'click', function (event) {

        var ua = navigator.userAgent;
        var event = (ua.match(/iPad/i)) ? "touchstart" : "click";

        // prevent ghost clicks on ipad
        infoBox.setContent('<div class="marker-wrapper animated fadeInDown"><div class="marker-title"> <a href="'+ this.link +'">'+ this.title +'</a> </div><div class="marker-content"><div class="two_third popup-content"><ul>'+ this.address +''+ this.phone +''+ this.mobile +''+ this.website +'</ul></div>'+ this.image +''+ this.readmore +'<div class="clearboth"></div> <div class="close" onClick=\'javascript:infoBox.close();\'><span class="icon-cancel"></span></div></div><span class="icon-down-dir"></span></div>');

        infoBox.open(map, this);
        map.setCenter(this.position);
        map.panTo(this.position);


    }); // end click even
} //end for

Any help would be appreciated. Thank you.

Why are you doing calculations for the latlang values? Just get the coordinates from Google Maps, they can be found by right clicking on the map and then hit 'whats here' and the coordinates appear in the info window. Hope that helps.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.