我一直在关注IBM的Grails和Google Maps教程,here
我注意到它适用于Google Maps API v2。我尝试使用v3语法做同样的事情,但我显然做错了什么。我在教程中得到了示例,因此它从db获取lat和lng。我现在在办公室,没有可用于粘贴的例子。
但问题是,我如何编写以下代码才能使用Google Maps v3。我回家后会更新帖子。
<script type="text/javascript">
var usCenterPoint = new GLatLng(39.833333,-98.583333) var usZoom = 4
function load(){ if(GBrowserIsCompatible()){ var map = new GMap2(document.getElementById(“map”)) map.setCenter(usCenterPoint,usZoom) map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl());
<g:each in="${airportList}" status="i" var="airport">
var point${airport.id} = new GLatLng(${airport.lat}, ${airport.lng})
var marker${airport.id} = new GMarker(point${airport.id})
marker${airport.id}.bindInfoWindowHtml("${airport.iata}<br/>${airport.name}")
map.addOverlay(marker${airport.id})
</g:each>
} }
我要做的就是在地图上的airportList中显示标记。 谢谢!
答案 0 :(得分:1)
我这样解决了。可能还有其他解决方案,但这可行。
function initialize() {
var myOptions = {
som options...
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
setMarkers(map, markers);
var markers = [];
g:each in="${airportList}" status="i" var="airport"
var latlng = new google.maps.LatLng(${airport.lat}, ${airport.lng});
var marker${airport.id} = new google.maps.Marker({
position: latlng,
map: map,
title:"${airport.name}",
icon: 'http://google-maps-icons.googlecode.com/files/factory.png',
});
g:each
希望这有帮助!你必须打开和关闭g:每个标签,但如果我添加“&lt;”和“&gt;”然后代码消失了。 :s