php - 带有动态生成数字的自定义 map 标记图标

标签 php javascript google-maps

我想为我的 Google map 添加编号的 map 标记,目前我正在使用 Google Charts API 方法动态创建编号标记。但是我无法通过该方法使用我自己的图标。

有没有办法使用我自己的自定义 map 标记图标,然后在其上面覆盖/有一个数字?

或者,是否有一种快速方法可以创建从数字 11000 的 1000 个 .PNG 标记?就像 Photoshop 中的批处理

最佳答案

我从我写的一篇文章中借用了这段代码,并对其进行了一些调整。您应该下载this image ,在 Photoshop 中稍微编辑一下,并将其放在与 PHP 脚本相同的目录中。调整脚本中的数字,直到得到像样的东西。

<?php
define("FONT_SIZE", 6);                            // font size in points
define("FONT_PATH", "c:/windows/fonts/arial.ttf"); // path to a ttf font file
define("FONT_COLOR", 0x00000000);                  // 4 byte color
                                                   // alpha  -- 0x00 thru 0x7F; solid thru transparent
                                                   // red    -- 0x00 thru 0xFF
                                                   // greeen -- 0x00 thru 0xFF
                                                   // blue -- 0x00 thru 0xFF
$text = $_GET["text"];
$gdimage = imagecreatefrompng("marker.png");
imagesavealpha($gdimage, true);
list($x0, $y0, , , $x1, $y1) = imagettfbbox(FONT_SIZE, 0, FONT_PATH, $text);
$imwide = imagesx($gdimage);
$imtall = imagesy($gdimage) - 14;                  // adjusted to exclude the "tail" of the marker
$bbwide = abs($x1 - $x0);
$bbtall = abs($y1 - $y0);
$tlx = ($imwide - $bbwide) >> 1; $tlx -= 1;        // top-left x of the box
$tly = ($imtall - $bbtall) >> 1; $tly -= 1;        // top-left y of the box
$bbx = $tlx - $x0;                                 // top-left x to bottom left x + adjust base point
$bby = $tly + $bbtall - $y0;                       // top-left y to bottom left y + adjust base point
imagettftext($gdimage, FONT_SIZE, 0, $bbx, $bby, FONT_COLOR, FONT_PATH, $text);
header("Content-Type: image/png");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 180) . " GMT");
imagepng($gdimage);
?>

我的系统上的示例输出:

/marker.php?text=9 /marker.php?text=99 /marker.php?text=999 /marker.php?text=AA

关于php - 带有动态生成数字的自定义 map 标记图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6464202/

相关文章:

php - 插入特定值更改记录

php - 防止php使用默认用户名和密码到mysql

javascript - JavaScript 中对象/数组的性能如何? (专门针对 Google V8)

google-maps - 旅游目的地API

javascript - 链接div到firefox中输入文本

php - Zend Framework 2 上的模块和模型组织

php - Android:通过 HttpResponse 从 PHP 服务器获取文件

javascript - d3js - 添加像工具提示一样的语音气泡?

javascript - 用于检查 radio 的 jQuery 事件

javascript - 有没有办法验证用户是否使用 Google 自动完成功能输入街道地址?