簡體   English   中英

谷歌地圖api播放框架位置標記

[英]Google map api play framework location marker

我在地圖上放置標記時遇到問題。 我有模型位置,我在其中保存坐標 x 和 y。 我從基地讀取列表中的所有坐標並將該列表發送到視圖中。 比我嘗試去查找所有列表並將標記放在 loc 上。 但它不起作用。 這是我的代碼。

@(places: java.util.List[models.Location])
@adminmain("Post Offices") {

<ol class="breadcrumb">
    <li><a href="@routes.Application.adminPanel()">Admin Panel</a></li>
    <li><a href="#">Maps</a></li>
    <li class="active">Location</li>
</ol>
<h1>Maps</h1
<div class="templatemo-maps">
    <div class="row">
        <div class="col-md-12 col-sm-12 margin-bottom-30">
            <div id="map" style="position: relative; height: 700px; width: auto"></div>

和腳本

<script type="text/javascript">
               var map = new google.maps.Map(document.getElementById('map'),           {
 zoom: 5,
 center: new google.maps.LatLng(43.8331, 18.3039),
 mapTypeId: google.maps.MapTypeId.ROADMAP});


   var i;
     for(i = 0; i<@places.size(); i++){
        var marker = new google.maps.Marker({
        position: new google.maps.LatLng(@places.get(i).x,@places.get(i).y),
    map: map
  });
}
map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the marker
window.setTimeout(function() {
  map.panTo(marker.getPosition());
}, 3000);});
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addDomListener(window, 'resize', function() {
map.setCenter(marker.getPosition());
});

如果有人對此有問題,我找到了解決方案。 你必須為 scala lang 中的每個語句編寫。 像這樣:

@for(place <- places) {

 marker = new google.maps.Marker({
    position: new google.maps.LatLng(@place.x
                , @place.y),
    map: map
    });
    }

它有效!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM