【问题标题】:Is there a way to add custom alt text to custom marker in google maps to improve SEO rating?有没有办法将自定义替代文本添加到谷歌地图中的自定义标记以提高 SEO 评级?
【发布时间】:2019-12-13 15:17:51
【问题描述】:

由于我公司的一位客户要求标记图像上的 alt 属性,我遇到了 google maps API 的问题。

我在 Google 官方文档中找不到任何内容(即:https://developers.google.com/maps/documentation/javascript/custom-markers),甚至在其他地方也找不到任何关于 google maps 标记的 alt 文本的信息。 就个人而言,我什至不知道它是否对 SEO 有影响(正如客户提到的第三方公司所说,因为他们在他们的网站上进行了一些 SEO 检查)。

我尝试使用来自 google 的示例并尝试添加一个假设的 alt 指令,但当然没有被采纳。

<!DOCTYPE html>
<html>
<head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
        /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
        #map {
            height: 100%;
        }
        /* Optional: Makes the sample page fill the window. */
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <div id="map"></div>
    <script>
        // Initialize and add the map
        function initMap() {
            // The location of Uluru
            var uluru = { lat: -25.344, lng: 131.036 };
            // The map, centered at Uluru
            var map = new google.maps.Map(
                document.getElementById('map'), { zoom: 4, center: uluru });
            // The marker, positioned at Uluru
            var marker = new google.maps.Marker({
                position: uluru,
                map: map,
                title: 'Uluru',
                alt: 'my alternate text goes here'
            });
        }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=***********************&callback=initMap" async defer></script>
</body>
</html>

渲染后的结果类似如下:

<img alt="" src="https://maps.gstatic.com/mapfiles/api-3/images/spotlight-poi2.png" draggable="false" usemap="#gmimap0" style="position: absolute; left: 0px; top: 0px; width: 27px; height: 43px; user-select: none; border: 0px; padding: 0px; margin: 0px; max-width: none; opacity: 1;">

有什么办法可以得到类似的东西:

<img alt="my alternate text goes here" src="https://maps.gstatic.com/mapfiles/api-3/images/spotlight-poi2.png" draggable="false" usemap="#gmimap0" style="position: absolute; left: 0px; top: 0px; width: 27px; height: 43px; user-select: none; border: 0px; padding: 0px; margin: 0px; max-width: none; opacity: 1;">

更新:

【问题讨论】:

  • 从上面的链接可以看出,地图存在不少可访问性问题。也就是说,我认为标记图像上缺少 alt 标签不会对网站的全球 SEO 产生(任何)影响。如果这是目标,还有其他方法可以以某种方式“引用”页面上的这些标记。听起来另一家公司只是进行了 SEO 检查,并在没有太多解释的情况下发送了结果......

标签: html google-maps google-maps-api-3 seo


【解决方案1】:

1) 我认为它不会对 SEO 产生任何影响:标记是动态呈现的,并且 afaik Google 只解析静态 HTML 和一些由 JS 呈现的内容,但我没有看到它运行 Maps API 调用,我'我在我的 API 流量中注意到了它)。在 JSON-LD 中生成页面摘要可能会更有帮助:https://json-ld.org/

2) 如果你必须添加一个 alt 标签(我不明白为什么)或者你想在标记旁边显示一个悬停工具提示,你必须考虑扩展 google.maps.OverlayView() 来创建你自己的自定义标记:这个对象有一个draw 原型方法,可以让你以任何你想要的方式在地图上放置任何东西:&lt;img alt=...&gt;&lt;div&gt; 等。

https://developers.google.com/maps/documentation/javascript/reference/overlay-view https://developers.google.com/maps/documentation/javascript/examples/overlay-simple

3) 既然您依赖 Google 正确解析 JS 输出:为什么不尝试添加 alt 标签 post-factum(地图加载后),如 (jQuery) $('img[alt=""]').attr('alt','Now I fixed it') ;)

【讨论】:

  • 除非 G 最近改变了它的引擎,它已经有好几年没有读取渲染的 js(即:searchengineland.com/… - 也......它无法索引 SPA,但它确实...... ) 另一方面,我可以看看draw()。我从来没有用过它。谢谢你的提示。
  • 我认为这更能说明 Google 所做的事情:seopressor.com/blog/… 我不认为它所做的是运行 Google Maps API 调用。我会将其视为我网站中的 API 调用流量...我确实建议您检查 JSON-LD,这是在页面中定义奇怪的交互式内容的正确方法,而不是强迫性地尝试将 alt 标记添加到任何图像你可以找到,但这只是我的 2 美分...
  • 感谢您的链接。它看起来很有希望和有趣。当我回家时,我会一直读下去。正如我在原帖中所说,我认为特定的alt 没有任何价值,或者它是否有某种影响,但是,在回复客户之前,他们支付的第三家公司据说是在说有些错误/不正确,我需要更加确定(因此这里有关于 SO 的问题)。我完全同意 JSON-LD,但是在当前系统上正确实现它太难了,所以我现在不能使用这种方法。
  • 这就是我添加seo标签的原因,也许你会得到更多关于此事的反馈。
  • 参见第三个想法 :)
猜你喜欢
  • 1970-01-01
  • 2017-06-04
  • 1970-01-01
  • 2013-08-21
  • 1970-01-01
  • 2016-09-20
  • 2014-06-04
相关资源
最近更新 更多