我一直在测试使用我的数据库中的标记创建交互式谷歌地图的所有不同方法。我非常接近使用javascript API。它将标记放置得很好,但是当它创建标签时我需要逃避角色'它被编码到'这杀死了javascript。我已经尝试了几种解码方式,如HtmlDecode(字符串)和$("")。html(name).text();但都没有用。如何在javascript中阻止编码或以某种方式解码?
这是地图代码
<script>
var map;
function initialize() {
// Create a simple map.
map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: { lat: 32.9393, lng: -117.0437 },
mapTypeId: google.maps.MapTypeId.TERRAIN
});
@siNetWebApplication.Models.siNetWebHelperFunctions.mapGetMarkers(Model.Runs.ToList())
}
google.maps.event.addDomListener(window, 'load', initialize);
这是构建地图标记列表的mapGetMarkers()函数
public static string mapGetMarkers(List<AverageNodeValues> runs)
{
decimal zero = 0;
var count = 0;
var limit = 20;
List<string> usedNodes = new List<string>();
StringBuilder builder = new StringBuilder();
foreach (AverageNodeValues run in runs)
{
if (!usedNodes.Contains(run.NodeID))
{
if (run.GPS_Lattitude != zero && run.GPS_Longitude != zero)
{
builder.Append("var marker")
.Append(run.NodeID)
.Append(" = new google.maps.Marker({ position: { lat: ")
.Append(run.GPS_Lattitude)
.Append(", lng: ")
.Append(run.GPS_Longitude)
.Append(" }, map: map }); ")
.Append("var info")
.Append(run.NodeID)
.Append(" = new google.maps.InfoWindow({ content: ")
.Append("\'")
.Append(run.NodeID)
.Append("\'")
.Append(", ")
.Append("\'")
.Append(@"click")
.Append("\'")
.Append(", function () { info")
.Append(run.NodeID)
.Append(".open(map, marker")
.Append(run.NodeID)
.Append("); }); ");
usedNodes.Add(run.NodeID);
count++;
}
if (count >= limit)
{
break;
}
}
}
return builder.ToString();
}
这就是html中的最终结果
var markerG0000112 = new google.maps.Marker({ position: { lat: 29.5672500000, lng: -98.2429816666 }, map: map }); var infoG0000112 = new google.maps.InfoWindow({ content: 'G0000112', 'click', function () { infoG0000112.open(map, markerG0000112); }); var markerG0000113 = new google.maps.Marker({ position: { lat: 29.5672566666, lng: -98.2419316666 }, map: map }); var infoG0000113 = new google.maps.InfoWindow({ content: 'G0000113', 'click', function () { infoG0000113.open(map, markerG0000113); }); var markerG0000102 = new google.maps.Marker({ position: { lat: 32.9393233333, lng: -117.0437383333 }, map: map }); var infoG0000102 = new google.maps.InfoWindow({ content: 'G0000102', 'click', function () { infoG0000102.open(map, markerG0000102); });