我正在尝试使用动态标记和动态infoWindows加载谷歌地图.基本上我有标记工作.infoWindows是可点击和可关闭的,但它们没有正确的内容.似乎每个infoWindow的内容是查询循环中找到的最后一条记录.你会看到这里发生了什么这是代码:
<script type="text/javascript">
//Load the Google Map with Options//
function initialize() {
var myLatlng = new google.maps.LatLng(42.48019996901214, -90.670166015625);
var myOptions = {
zoom: 6,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//Begin query loop to set the markers and infoWindow content//
<cfoutput query="GetCoord">
var LatLng = new google.maps.LatLng(#Client_Lat#, #Client_Lng#);
var marker = new google.maps.Marker({
position: LatLng,
map: map,
title: "#Client_Company#"
});
var contentString = '<p><b>#Client_Company#</b><br>'+
'#Client_Address#<br>'+
'#Client_City#, #Client_State# #Client_Zip#<br>'+
'<a href="member_detail.cfm?ID=#Client_ID#">View …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个小型应用程序,它将城市和州以及地理位置解析为纬度/经度.现在我正在使用Google Map的API,ColdFusion和SQL Server.基本上,城市和州的字段都在数据库表格中,我想要获取这些位置并将标记放在谷歌地图上,以显示它们的位置.
这是我执行地理编码的代码,查看页面源代码显示它正确循环查询并在地址字段中放置位置("奥马哈,NE"),但没有标记或地图,正在页面上显示:
function codeAddress() {
<cfloop query="GetLocations">
var address = document.getElementById(<cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput>).value;
if (geocoder) {
geocoder.geocode( {<cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput>: address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: <cfoutput>#Trim(hometown)#,#Trim(state)#</cfoutput>
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</cfloop> }
Run Code Online (Sandbox Code Playgroud)
以下是初始化地图的代码:
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(42.4167,-90.4290);
var myOptions = {
zoom: …Run Code Online (Sandbox Code Playgroud)