谷歌地图:无法在包含数据库标记的地图中添加自动搜索选项
Google Maps: Unable to add auto search options in map contains marks from database
我试图在谷歌地图中添加数据库中的存储标记,并自动搜索缩放特定位置的选项。
我能够从数据库中添加标记,但我无法在地图中添加自动搜索选项包含来自数据库的标记。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Maplocator.aspx.cs" Inherits="Maplocator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Show/Add multiple markers to Google Maps from database in asp.net website</title>
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0;
padding: 0
}
#map_canvas {
height: 100%
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MyKey&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var markers = JSON.parse('<%=ConvertDataTabletoString() %>');
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var input = (document.getElementById('txtsearch'));
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
var searchBox = new google.maps.places.SearchBox((input));
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(function(marker, data) {
// Attaching a click event to the current marker
google.maps.event.addListener(marker, "click", function(e) {
infoWindow.setContent(data.Descriptions);
infoWindow.open(map, marker);
});
})(marker, data);
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = map.getBounds();
searchBox.setBounds(bounds);
});
}
}
</script>
</head>
<body onload="initialize()">
<form id="form1" runat="server">
<div style="width: 500px; height: 200px"> </div>
<input id="txtsearch" class="apply" type="text" placeholder="Enter Search Place e.g C# Corner Noida" />
<div id="map_canvas" style="width: 600px; height: 500px"></div>
</form>
</body>
</html>
背后的代码:
public string ConvertDataTabletoString()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select title=City,lat=latitude,lng=longitude,Descriptions from LocationDetails", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
}
}
}
在Place Autocomplete Results
中提到Place Autocomplete响应不包括您可能在搜索结果或位置详细信息中看到的scope或alt_ids字段。这是因为Autocomplete只返回google作用域的位置id。它不返回尚未被Google Places数据库接受的应用范围的位置id。
另外,当你添加一个位置时,
新的地方也进入一个审核队列,以考虑谷歌地图
这意味着,你只能在自动搜索选项中看到那些添加的标记或位置,如果他们通过审核过程并被接受进入谷歌位置数据库。
重要提示:
为了使该位置更有可能通过审核过程并被添加到Google Maps数据库中,添加请求应该包含尽可能多的信息。特别是,以下字段最有可能提高通过审核过程的机会:电话号码、地址和网站。
相关文章:
- 谷歌地图可以't添加正确的标记ID
- 使用ASP.NET将谷歌地图添加到项目中,并从数据库中检索位置
- 在SVG地图上添加水的渐变,就像在谷歌地图(PHP/JS)中一样
- Javascript/谷歌图表-为谷歌地图添加标记过滤器
- 必应地图没有'当我向函数添加另一个参数时,t显示
- 如何在谷歌地图上为单个位置添加多个标记
- 谷歌地图/SQL-添加链接到信息面板中的字段
- jQuery美国地图插件-为每个点击状态添加unique.html
- 如何在谷歌地图上添加带有Instagram图片的多个标记
- 无法在一个页面中添加多个谷歌地图
- 如何在地图加载后向谷歌地图添加标记
- 将地理 JSON 要素属性添加到地图框弹出窗口
- 谷歌地图API v3 - 初始化后添加标记
- 谷歌地图api:如何将我自己的标记添加到地图
- 谷歌地图:将带有信息框的多个标记添加到自定义地图
- 将ID添加到地图框标记
- 在我的谷歌地图代码中,我添加地图样式的代码
- 添加地图标记与谷歌地图JS SDK没有纬度/经度
- 在HTML5中为平面图添加地图标记
- 我想在Div(动态创建)的innerHTML中添加地图