Google maps 我需要使用位置[2](状态字段)根据SQL数据库字段为标记着色 //从SQL数据库填充位置 变量位置= [['', ' , ','','','' ],]; var map=new google.maps.map(document.getElementById('map'){ 缩放:10, 中心:新google.maps.LatLng(28.4811689,-81.36875), mapTypeId:google.maps.mapTypeId.ROADMAP }); var infowindow=new google.maps.infowindow(); var geocoder=new google.maps.geocoder(); var标记,i; 对于(i=0;i
将在循环内覆盖Google maps 我需要使用位置[2](状态字段)根据SQL数据库字段为标记着色 //从SQL数据库填充位置 变量位置= [['', ' , ','','','' ],]; var map=new google.maps.map(document.getElementById('map'){ 缩放:10, 中心:新google.maps.LatLng(28.4811689,-81.36875), mapTypeId:google.maps.mapTypeId.ROADMAP }); var infowindow=new google.maps.infowindow(); var geocoder=new google.maps.geocoder(); var标记,i; 对于(i=0;i,google-maps,Google Maps,将在循环内覆盖图标-变量。改为将颜色作为参数传递给createMarker: <div id="map" style="width: 100%; height: 100%;"></div> <script type="text/javascript"> //Populate locations from SQL database var locations = [<ASP:Repeat
图标
-变量。改为将颜色作为参数传递给createMarker:
<div id="map" style="width: 100%;
height: 100%;"></div>
<script type="text/javascript">
//Populate locations from SQL database
var locations =
[<ASP:Repeater id="MyRepeater" runat="server"><ItemTemplate>['<%# DataBinder.Eval(Container.DataItem, "City") %>', ' <%# DataBinder.Eval(Container.DataItem, "StreetAddress") %>, <%# DataBinder.Eval(Container.DataItem, "State") %>, <%# DataBinder.Eval(Container.DataItem, "Zipcode") %>','<%# DataBinder.Eval(Container.DataItem, "Status") %>','<%# DataBinder.Eval(Container.DataItem, "CompanyName") %>','<%# DataBinder.Eval(Container.DataItem, "Id") %>' ],</ItemTemplate></ASP:Repeater>];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(28.4811689,-81.36875),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
var marker, i;
for (i = 0; i < locations.length; i++) {
geocodeAddress(locations[i]);
icon = "http://maps.google.com/mapfiles/ms/icons/" + location[2] + ".png"
}
function geocodeAddress(location) {
setTimeout( function () {
geocoder.geocode( { 'address': location[1]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
createMarker(results[0].geometry.location,location[0]+"<br>"+location[1]+"<br><div style=background-color:"+location[2]+";></div><br>"+location[3]+"<br><a target='_blank' href='editrequest.aspx?Id="+location[4]);
}
else
{
alert("some problem in geocode" + status);
}
}); }, i * 500);
}
function createMarker(latlng,html){
var marker = new google.maps.Marker({
position: latlng,
map: map,
});
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.setContent(html);
infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'mouseout', function() {
infowindow.close();
});
}
</script>
if (status == google.maps.GeocoderStatus.OK) {
createMarker(results[0].geometry.location,
'the infowindowhtml',
location[4]//as it seems the color is not location[2]
);
}
它工作了!我必须修改我的SQL语句,将“Status”转换为所有小写,使用
LOWER(Status)AS StatusL
,然后将位置[2]
从
更改为
我还必须将超过查询限制的超时时间从500增加到1500,并在createMarker函数中将
+color+
更改为+color+
。我是stackoverflow新手,因此请原谅格式问题。位置[2]此C#field'是否在位置中。它是一个颜色字段,值为绿色、黄色等。我想根据该字段值为标记图标上色。感谢帮助geocodezip,我需要做什么来更正格式?它正确地将参数传递给createMarker函数,出于某种原因,它刚刚启动了OVER查询限制标志。如果我增加超时,它不会显示任何标记。我想我已经解决了。我的颜色字段使用大写字母“绿色”,当我硬编码时,它不起作用。我可能需要在我的SQL语句或.js中将其转换为小写。它起作用了!我必须修改我的SQL语句,使用“LOWER(Status)”将“Status”转换为所有小写作为StatusL“然后将位置[2]更改为from。我还必须将超过查询限制的超时时间从500增加到1500,并在createMarker函数中将“+color+”更改为“+color+”。Molle博士,非常感谢您!
function createMarker(latlng,html,color){
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon : "http://maps.google.com/mapfiles/ms/icons/" + color + ".png"
});
//mouseover & mouseout....
}