C# 使用谷歌地图API的位置标记问题
我正在使用GoogleMapsAPI在.Net平台上显示位置标记。我已经将纬度、经度、城市和州信息存储在数据库中,如果我添加第7个数据库条目作为纬度和经度,我将面临地图和标记不显示的问题 下面是.aspx的代码和隐藏代码 .aspx:C# 使用谷歌地图API的位置标记问题,c#,asp.net,google-maps,google-maps-api-3,C#,Asp.net,Google Maps,Google Maps Api 3,我正在使用GoogleMapsAPI在.Net平台上显示位置标记。我已经将纬度、经度、城市和州信息存储在数据库中,如果我添加第7个数据库条目作为纬度和经度,我将面临地图和标记不显示的问题 下面是.aspx的代码和隐藏代码 .aspx: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title> Goo
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
Google Map Locations
</title>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=My_Key&sensor=false">
</script>
</head>
<body onload="initialize()">
<form id="form1" runat="server">
<div id="mapArea" style="width: 700px; height: 700px;">
</div>
<asp:Label ID="Label11" runat="server"></asp:Label>
</form>
</body>
</html>
namespace GoogleMaps
{
public partial class GoogleMaps : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string markers = GetLocationMarkers();
Label1.Text = @"
<script type='text/javascript'>
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(39.948427, -101.836428),
zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var myMap = new google.maps.Map(document.getElementById('mapArea'),
mapOptions);"
+ markers +
@"}
</script>";
}
protected string GetLocationMarkers()
{
string markers = "";
using (SqlConnection con = new
SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ConnectionString))
{
SqlCommand cmd = new SqlCommand(
"SELECT Latitude, Longitude, City FROM Map", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
int i = 0;
while (reader.Read())
{
i++;
markers += @"var marker"+i.ToString()+ @" =
new google.maps.Marker({
position:google.maps.LatLng("+reader["Latitude"].ToString() +"
, "+
reader["Longitude"].ToString() +")," +
@"map: myMap,title:'"+reader["City"].ToString()+
"'});";
}
}
return markers;
}
}
}
但当数据库中只有6个条目时,我在城市名称后面看不到\r\n,例如:在下面的调试输出中:在Orlando之后
markers "var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(32.692383, -114.626648),
map: myMap, title:'Yuma'});
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(38.250095, -122.040001),
map: myMap, title:'Fairfield'});
var marker3 = new google.maps.Marker({
position: new google.maps.LatLng(26.56225, -81.948121),
map: myMap, title:'Cape Coral'});
var marker4 = new google.maps.Marker({
position: new google.maps.LatLng(45.52263, -122.681208),
map: myMap, title:'Portland'});
var marker5 = new google.maps.Marker({
position: new google.maps.LatLng(37.810308, -85.981012),
map: myMap, title:'Vine Grove'});
var marker6 = new google.maps.Marker({
position: new google.maps.LatLng(28.540228, -81.385238),
map: myMap, title:'Orlando'});
是什么导致谷歌地图无法显示?
数据库中只有6个条目,地图上显示的标记没有问题。任何答案都将不胜感激。可能是转义序列问题
尝试仅选择第7个城市的风笛声,检查问题是否与字符串内容有关。在此标记中,si not show尝试更新此条目删除“\r\n”字符不要使用标签将脚本添加到页面上!只需将脚本放在页面标记(.aspx)上。如果需要将数据从服务器端传递到脚本中,可以通过隐藏字段将其插入脚本中,或将其嵌入到标记页面上脚本中的变量中。
markers "var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(32.692383, -114.626648),
map: myMap, title:'Yuma'});
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(38.250095, -122.040001),
map: myMap, title:'Fairfield'});
var marker3 = new google.maps.Marker({
position: new google.maps.LatLng(26.56225, -81.948121),
map: myMap, title:'Cape Coral'});
var marker4 = new google.maps.Marker({
position: new google.maps.LatLng(45.52263, -122.681208),
map: myMap, title:'Portland'});
var marker5 = new google.maps.Marker({
position: new google.maps.LatLng(37.810308, -85.981012),
map: myMap, title:'Vine Grove'});
var marker6 = new google.maps.Marker({
position: new google.maps.LatLng(28.540228, -81.385238),
map: myMap, title:'Orlando'});