如何以编程方式在谷歌地图中添加多个标记
How do I add multiple markers in Google Maps programmatically?
我的ASPX页面中有以下代码:
<section id="google-map" class="gmap slider-parallax"></section>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/jquery.gmap.js"></script>
<script type="text/javascript">
$('#google-map').gMap({
address: 'riyadh, saudi arabia',
maptype: 'ROADMAP',
zoom: 6,
markers: [{
address: "riyadh, saudi arabia",
html: '<div style="width: 300px;"><h4 style="margin-bottom: 8px;">Hi, we''re <span>Envato</span></h4><p class="nobottommargin">Our mission is to help people to <strong>earn</strong> and to <strong>learn</strong> online. We operate <strong>marketplaces</strong> where hundreds of thousands of people buy and sell digital goods every day, and a network of educational blogs where millions learn <strong>creative skills</strong>.</p></div>',
icon: { image: "images/icons/map-icon-red.png", iconsize: [32, 39], iconanchor: [13, 39] }
},
{
address: "Al Uyaynah العيينة",
html: '<div style="width: 300px;"><h4 style="margin-bottom: 8px;">Hi, we''re <span>Envato</span></h4><p class="nobottommargin">Ring Road, Al Abageyah, Qism El-KhalifaOur mission is to help people to <strong>earn</strong> and to <strong>learn</strong> online. We operate <strong>marketplaces</strong> where hundreds of thousands of people buy and sell digital goods every day, and a network of educational blogs where millions learn <strong>creative skills</strong>.</p></div>',
icon: { image: "images/icons/map-icon-red.png", iconsize: [32, 39], iconanchor: [13, 39] }
},
{
address: "Riyadh Province, Saudi Arabia",
html: '<div style="width: 300px;"><h4 style="margin-bottom: 8px;">Hi, we''re <span>Envato</span></h4><p class="nobottommargin">Ring Road, Al Abageyah, Qism El-KhalifaOur mission is to help people to <strong>earn</strong> and to <strong>learn</strong> online. We operate <strong>marketplaces</strong> where hundreds of thousands of people buy and sell digital goods every day, and a network of educational blogs where millions learn <strong>creative skills</strong>.</p></div>',
icon: { image: "images/icons/map-icon-red.png", iconsize: [32, 39], iconanchor: [13, 39] }
}]
,
doubleclickzoom: false,
controls: {
panControl: true,
zoomControl: true,
mapTypeControl: true,
scaleControl: false,
streetViewControl: false,
overviewMapControl: false
}
});
</script>
我应该从数据库加载地图标记。如何使用C#更改以下代码?
markers: [{
address: "riyadh, saudi arabia",
html: '<div style="width: 300px;"><h4 style="margin-bottom: 8px;">Hi, we''re <span>Envato</span></h4><p class="nobottommargin">Our mission is to help people to <strong>earn</strong> and to <strong>learn</strong> online. We operate <strong>marketplaces</strong> where hundreds of thousands of people buy and sell digital goods every day, and a network of educational blogs where millions learn <strong>creative skills</strong>.</p></div>',
icon: {
image: "images/icons/map-icon-red.png",
iconsize: [32, 39],
iconanchor: [13, 39]
}
}, {
address: "Al Uyaynah العيينة",
html: '<div style="width: 300px;"><h4 style="margin-bottom: 8px;">Hi, we''re <span>Envato</span></h4><p class="nobottommargin">Ring Road, Al Abageyah, Qism El-KhalifaOur mission is to help people to <strong>earn</strong> and to <strong>learn</strong> online. We operate <strong>marketplaces</strong> where hundreds of thousands of people buy and sell digital goods every day, and a network of educational blogs where millions learn <strong>creative skills</strong>.</p></div>',
icon: {
image: "images/icons/map-icon-red.png",
iconsize: [32, 39],
iconanchor: [13, 39]
}
}, {
address: "Riyadh Province, Saudi Arabia",
html: '<div style="width: 300px;"><h4 style="margin-bottom: 8px;">Hi, we''re <span>Envato</span></h4><p class="nobottommargin">Ring Road, Al Abageyah, Qism El-KhalifaOur mission is to help people to <strong>earn</strong> and to <strong>learn</strong> online. We operate <strong>marketplaces</strong> where hundreds of thousands of people buy and sell digital goods every day, and a network of educational blogs where millions learn <strong>creative skills</strong>.</p></div>',
icon: {
image: "images/icons/map-icon-red.png",
iconsize: [32, 39],
iconanchor: [13, 39]
}
}]
关于第二个问题,您应该使用web服务并将数据表转换为JSON格式,然后才能使用JavaScript中的JSON。
WEB服务
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public void GetMaps(string mapId)
{
DataTable dt = new DataTable();
dt = dataClass.data.get(mapId);
string jsonString = string.Empty;
jsonString = JsonConvert.SerializeObject(dt);
Context.Response.Clear();
Context.Response.ContentType = "application/json";
Context.Response.Flush();
Context.Response.Write(jsonString);
}
通过以下代码,您可以从Web服务获得JSON格式
var senderData = { mapId: "1" }
$.ajax({
type: "POST",
url: "/webservice.asmx/GetMaps",
processData: false,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(senderData),
success: function (response) {
//JSON format is in items
var items = eval(response.d);
},
error: function (error) {
console.log(error);
}
});
相关文章:
- 谷歌地图可以't添加正确的标记ID
- 使用ASP.NET将谷歌地图添加到项目中,并从数据库中检索位置
- 在SVG地图上添加水的渐变,就像在谷歌地图(PHP/JS)中一样
- 如何在angular.js控制器中添加谷歌地图
- 如何在现有标记下方添加谷歌地图标记
- 从嵌套数组添加谷歌地图标记
- 如何正确添加谷歌地图 api 密钥
- 如何使用PHP,jquery在页面中添加谷歌地图
- 在带有地理位置的jquery移动网站中添加谷歌地图
- 当使用dburles:Google Maps Meteor包时,我如何添加谷歌地图可视化库
- 如何动态添加谷歌地图
- 在Openlayer中添加谷歌地图层.要求是什么
- 在我的流星应用程序上添加谷歌地图
- 使用jQuery动态添加谷歌地图V3标记
- 在Svg中添加谷歌地图
- 为什么在调试模式外添加谷歌地图会导致d3.js刷重绘崩溃?
- 如何从GWT代码中添加谷歌地图对象
- 如何在jQuery应用程序的两个选项卡中添加谷歌地图
- 您如何使用谷歌地图 API 与摩卡测试,因为没有 html 来添加谷歌地图 API 所需的脚本标签
- 在localStorage中添加谷歌地图标记