Google Maps Marker disappeared upon relocation to the current application

After reading several articles on missing markers, I'm still facing a unique issue that doesn't seem to have a clear solution. The problem arises when attempting to render a basic map with just one marker and a fixed location. Despite Chrome dev debugging indicating the presence of the marker with all properties set correctly, it simply won't display on the map. Strangely enough, adding an Infowindow works flawlessly using the same map and marker setup.

Here's the simplified code for a webpage displaying a U.S. map with a single centered marker:


  <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

  <div style="height:500px" id="map-canvas"></div>

  <script>
      var myMap;
      var marker;

  function mapInitialize() {
      var latlng = new google.maps.LatLng(35, -96);
      var mapOptions = {
      zoom: 4,
      center: latlng,
      mapTypeId: 'roadmap'
  }

  myMap = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  marker = new google.maps.Marker({
      map: myMap,
      position: latlng,
      title: "Hello World!",
      visible: true
  });

  google.maps.event.addDomListener(window, 'load', mapInitialize);

</script>

In a Backbone map view context, things start to get a bit trickier as there might be a need for a marker collection, based on other similar cases. Although I've simplified the code by moving everything into an initialize function for troubleshooting purposes, the issue persists with just one marker.

var MapView = Backbone.View.extend({

 el: "body",

 initialize: function() {

     var myMap;
     var marker;
     var latlng = new google.maps.LatLng(35, -96);
     var mapOptions = {
         zoom: 4,
         center: latlng,
         mapTypeId: 'roadmap'
   }

   myMap = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
   marker = new google.maps.Marker({
       map: myMap,
       position: latlng,
       title: "Hello World!",
       visible: true
   });

 }
});

The comparison in Chrome Dev tools between the plain page scenario (/map.html) and the Backbone implementation (/#/map, calling for a new MapView creation) confirms that the marker's properties are correctly set and associated with the map element.

Answer №1

While troubleshooting an issue in my Backbone code within an existing application, I decided to test if Backbone itself was the culprit by integrating the map view into a new Backbone app without any of the existing code. Surprisingly, the marker displayed correctly in this fresh environment.

Upon inspecting the elements generated, I identified the specific canvas object responsible for rendering the marker within the Google maps canvas.

<div style="-webkit-transform: translateZ(0px); position: absolute; left: 0px; top: 0px; 
 z-index: 103; width: 100%;”>
    <div style="position: absolute; left: 0px; top: 0px; z-index: -1;”>
        <div style="position: absolute; left: 0px; top: 0px; z-index: 1;”>
            <div style="width: 256px; height: 256 px; overflow: hidden; 
             -webkit-transform: translateZ(0px); position: absolute; left: 230px; 
              top: 27px;”>
                <canvas style="-webkit-user-select: none; position: absolute; 
                 left: 0px; top: 0px; height: 256 px; width: 256 px;”>

The issue was resolved by explicitly setting the display style property of the canvas element to something other than "none." Why did this fix the problem? It turns out that buried deep in the CSS of the extensive application was

canvas {
  display: none;
}

This particular line of CSS was intended for a module unrelated to Google maps within the application.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to make ionic slides adhere to column width

I've been immersing myself in learning the latest versions of AngularJS and Ionic through practical application. I am currently working on a page that uses ionic rows and columns to display JSON data. The layout includes a 50/50 column setup, with a t ...

Please explain the display property used in Bootstrap input groups

I have been working on implementing a button that toggles the visibility of a datepicker when clicked. <a class="btn btn-primary btn-lg mr-5" href="../Stores/stalls.html">Check Current Operating Stalls </a> <div style="vertical-align: t ...

Using CSS units such as vw, vh, or percentage to specify height is not possible

In my Ionic app, I am adjusting the width and height of a div based on the viewport dimensions. This setup functions correctly on the browser and Android 4.4 devices. However, it does not work as expected on Android 4.2 (the height is constrained to the te ...

What is the best way to align the text in the center without centering the numbers in an HTML ordered list?

I am currently working on a small widget for a webpage that displays steps in reverse order. My plan is to use an ol element and adjust the value attribute on each li tag to make the numbering of the ordered list reversed. Everything seems to be going smoo ...

Designing an image transformation page by segmenting the image into fragments

Does anyone have insight into the creation process of websites like this one? Are there any plugins or tools that can assist in building something similar? ...

Refrain from showing content beneath a certain element

Is there a way to hide all content that appears after a specific element, such as a particular class of div? The issue I am facing involves using a 1&1 webpage builder with a restrictive layout-template enforced by my boss. I am trying to remove the foote ...

The space residing above my primary container division

I recently finished creating a basic web app, but I'm encountering an issue with the smallest media query where there is an unwanted top gap. Despite trying multiple methods and researching solutions online, I have not been able to resolve this proble ...

What is the best way to include the border-radius CSS property to a dropdown element in Ant Design?

Adding the border-radius CSS property to my dropdown component from ant design has been a bit challenging for me. I attempted to modify the antd-css file and include a style object directly into the component, but unfortunately, I did not achieve the des ...

Boosting your website with a slick Bootstrap 4 responsive menu that easily accommodates additional

I have incorporated a main menu in my website using the Bootstrap 4 navbar. However, I also have an additional div (.social-navbar) containing some extra menu items that I want to RELOCATE and INSERT into the Bootstrap menu only on mobile devices. Essentia ...

When the screen is resized, the embedded iframe moves smoothly to the left side

I recently created a projects page, but I am facing an issue with the iframe embed. Whenever the screen is resized, it keeps shifting to the left. However, what I really want is for it to be centered instead of being on the left side: https://i.stack.imgu ...

Add a blur effect to a specific region of an SVG image

I have a complex, dynamic SVG image created using jQuery SVG. I want to create a "popup" area that appears on top of all SVG elements in the canvas. To achieve a modern translucent iOS7 style, I would like to add a blur filter to everything beneath the pop ...

Formatting code within an HTML document

I am attempting to customize a stock widget that I obtained from financialcontent.com. My current approach involves using Bootstrap for styling purposes. To incorporate the widget into a div, I found it necessary to embed the script directly within the HT ...

Box-sizing:border-box causing CSS padding problem in Firefox

Something strange is happening in Firefox, it seems like the debug console is not telling the truth or there's something I'm not seeing. Here's the CSS for the body tag: html, body { width: 100%; } body { padding: 5% 10% 0 10%; ...

What steps do I need to take to create a custom image for a website?

I'm looking for a way to create a website image using just code, without the need for an actual image file or image tag. Is there a method to do this? Would I use CSS, Javascript, or HTML5 for this task? If using JavaScript to dynamically generate the ...

"Interact with jQuery by sliding side to side or in a circular motion

I am in need of assistance with sliding images using jQuery back and forth, or making them go round in a loop. Currently, the images slide up to the last element and then swiftly return to the first div, which is not visually appealing at all. I understa ...

Having trouble aligning the image to the center

After researching and trying various solutions suggested for aligning an image, I am still unable to get it to align as desired. Here is the HTML code snippet: <section> <img class="seattle" src="img/Seattle Pier.jpg" alt="Seattle docks"> ...

If you click outside of a Div element, the Div element will close

I am looking for a way to implement a function that will hide a specific div when I click outside of its area. The div is initially set to Position: none and can be made visible using the following function: Div Element: <div id="TopBarBoxInfo1" oncli ...

The <span> tag creating a surprise gap following a word

Using Angular4, I've come across an odd issue where one of my span elements is adding an extra space to the end of words like this: https://i.stack.imgur.com/H4TD7.png The only CSS properties that are set include font-family, -webkit-font-smoothing, ...

Tips on making Material-UI Drawer compress other content when it is open

Seeking assistance from those familiar with CSS and Material UI! I'm currently working on implementing a Material UI Drawer component that doesn't just slide out over the top of the page content, but actually causes the page content to adjust aro ...

fixed footer with fixed height on parent container

I have successfully implemented a sticky footer on my web pages by following specific instructions. http://css-tricks.com/snippets/css/sticky-footer/ The recommended approach includes using min-height:100% and not specifying the height property. .page-w ...