简体   繁体   English

如何使用两个词命名 Google 地图标记图标类型?

[英]How to name Google Map Marker Icon types using two words?

I'm developing a Google map to display job locations using custom Marker Icons.我正在开发 Google 地图以使用自定义标记图标显示工作地点。

Here's a snippet of the code that I am using to set up the variable 'markerIcon' and the 'type' name ( Administrative ):这是我用来设置变量“markerIcon”和“类型”名称(管理)的代码片段:

BEFORE

 var markerIcon = { Administrative: { url: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png' // scaledSize: new google.maps.Size(80, 80), // origin: new google.maps.Point(0, 0), // anchor: new google.maps.Point(32,65), // labelOrigin: new google.maps.Point(40,33) } };

This is fine, so here's a snippet that doesn't work with the var 'type' name Administrative and Clerical :这很好,所以这里的代码片段不适用于 var 'type' 名称Administrative 和 Clerical

AFTER

 var markerIcon = { Administrative and Clerical: { url: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png' // scaledSize: new google.maps.Size(80, 80), // origin: new google.maps.Point(0, 0), // anchor: new google.maps.Point(32,65), // labelOrigin: new google.maps.Point(40,33) } };

This is the problem I am experiencing.这是我遇到的问题。 The use of more than one word and with spaces.使用多个单词并带有空格。

Below is the function that creates the marker:下面是创建标记的函数:

 function createMarker(latlng, name, company, address, type, jobdesc) { var jobButton = "<a class='btn btn-success btn-sm mt-2' role='button' href='/public/job_details_demo.php?" + "title=" + name + "'" + "target='_blank'>View Job" + "</a>"; var html = "<h5 class='mb-0'>" + name + "</h5>" + "<h6 class='mb-0'>" + company + "</h6>" + "<p><b>" + address + "</b></p>" + "<b>Job Details:</b></br>" + jobdesc + "</p>" + jobButton; var icon = markerIcon[type] || {}; var marker = new google.maps.Marker({ map: map, position: latlng, icon: icon.url }); google.maps.event.addListener(marker, 'click', function () { infoWindow.setContent(html); infoWindow.open(map, marker); }); markers.push(marker); }

To display the icons, I query the database to retrieve the 'jobsector_name' AS type using SQL.为了显示图标,我查询数据库以使用 SQL 检索“jobsector_name”AS 类型。 This works fine and the Marker Icons show up.这工作正常,并显示标记图标。

However, I need to use more than one word for the jobsector names, for example, 'Administrative and Clerical'.但是,对于工作部门名称,我需要使用多个词,例如“行政和文书”。 When I change the type to this name in the database and the Marker Icon name, the markers don't show, and no errors are shown in the Chrome console.当我在数据库中将类型更改为此名称和标记图标名称时,标记不会显示,Chrome 控制台中也不会显示任何错误。

My question is, how do I solve the problem of using two or more words for the Marker Icon type names?我的问题是,如何解决标记图标类型名称使用两个或多个单词的问题?

I've tried special characters like %20, but unsurprisingly the code hates any special characters.我尝试过像 %20 这样的特殊字符,但不出所料,代码讨厌任何特殊字符。 I've also tried referencing numbers, but they don't show and I've tried concatenating two variables, but don't know how to reference a variable inside another variable for this type of operation.我也尝试引用的数字,但他们不显示我尝试了连接两个变量,但不知道如何引用变量的另一个变量中的这种类型的操作。

SOLVED: I added '_' underscores between each word (both in the MarkerIcon type and database column values) and then used PHP command 'str_replace', when displaying the name on the page.已解决:我在每个单词之间添加了“_”下划线(在 MarkerIcon 类型和数据库列值中),然后在页面上显示名称时使用 PHP 命令“str_replace”。

$jobsector = str_replace("_", " ", $row['jobsector_name']);

PHP Manual - str_replace — Replace all occurrences of the search string with the replacement string PHP 手册 - str_replace — 用替换字符串替换所有出现的搜索字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM