将文字添加到Google地图 [英] Add text to Google Maps

查看:131
本文介绍了将文字添加到Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用API​​ V3时,如何在Google地图的右下角添加文字或超链接。也就是说,在下面的屏幕截图中显示的地图数据(c)2014 Google旁边添加文本或超链接。

How can I add text or hyper-links to the bottom right of Google Maps when using API V3. That is, add text or hyper-links next to "Map data (c)2014 Google" shown in the screen shot below.

以下是我的代码:

Here is my code:

<!DOCTYPE html>
<html>
  <head>
    <title>EC Bus Locations</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see a blank space instead of the map, this
// is probably because you have denied permission for location sharing.

var markers = [];
var map;

function initialize() {

  function getLocation()
  {
    $.get( "http://54.86.161.214/EC_bus_app/get_location.php", function( data ) {
      markers=[];
      var buses = data;
      var number_of_buses = buses.slice(0,1);
      buses = buses.slice(2);
      buses = buses.slice(0,-1);

      var bus_coordinates_and_numbers = buses.split(/[ ]+/);
      var length_of_array = bus_coordinates_and_numbers.length;

    // Turn a single dimensional array into a multi-dimensional array

      for (var index = 0; index < bus_coordinates_and_numbers.length; index+= 3)
          markers.push( bus_coordinates_and_numbers.slice(index, index + 3) );      
    });
  }

  getLocation();
  setInterval(getLocation, 5000);

  var mapOptions = {
    zoom: 16
  };
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

var image = "icon_97.png";
var busMarker = new google.maps.Marker;
var allMarkers = [];

  function draw()
  { 
    removeMarker();
    for (i=0;i<markers.length; i = i + 1){
      var x = markers[i][0];
      var y = markers[i][1];
      var myLatlng = new google.maps.LatLng(x,y);
      busMarker = new google.maps.Marker({
          position: myLatlng,
          icon: image,
          title: markers[i][2]
      });
      busMarker.setMap(map);   
      allMarkers.push(busMarker);
    }  
  }

  function removeMarker() 
  {
    if (allMarkers) {
        for (i=0; i < allMarkers.length; i++) {
            allMarkers[i].setMap(null);
        }
    allMarkers.length = 0;
    }
  }

  setTimeout(draw, 1000);
  setInterval(draw, 5000);

  // Try HTML5 geolocation
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = new google.maps.LatLng(position.coords.latitude,
                                       position.coords.longitude);

      var infowindow = new google.maps.InfoWindow({
        map: map,
        position: pos,
        content: 'Your location'
      });

      map.setCenter(pos);
    }, function() {
      handleNoGeolocation(true);
    });
  } else {
    // Browser doesn't support Geolocation
    handleNoGeolocation(false);
  }
}

function handleNoGeolocation(errorFlag) {
  if (errorFlag) {
    var content = 'Error: The Geolocation service failed.';
  } else {
    var content = 'Error: Your browser doesn\'t support geolocation.';
  }

  var options = {
    map: map,
    position: new google.maps.LatLng(60, 105),
    content: content
  };

  var infowindow = new google.maps.InfoWindow(options);
  map.setCenter(options.position);
}

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

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>


推荐答案

解决方案实际上非常简单,标记图标的图像。作为Google Chart Tools的一部分,您可以生成包含字母或数字的标记,还可以更改标记和字体颜色。
看看这里。
http://biostall.com/adding - 数字或字母到谷歌地图的api标记

The solution is actually quite simple and simply involves you using an image for the marker icons. As part of Google Chart Tools you can generate markers that contain a letter or number, as well change the marker and font colors. Take a look at here. http://biostall.com/adding-number-or-letters-to-google-maps-api-markers

这篇关于将文字添加到Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆