[英]Google map api play framework location marker
I have problem with putting marker on map.我在地图上放置标记时遇到问题。 I have model Location where i save coordinates x and y.我有模型位置,我在其中保存坐标 x 和 y。 I read from base all coordinates in list and send that list in view.我从基地读取列表中的所有坐标并将该列表发送到视图中。 Than I tried to go trought all list and put markers on loc.比我尝试去查找所有列表并将标记放在 loc 上。 But it doesnt work.但它不起作用。 Here is my code.这是我的代码。
@(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>
AND SCRIPT和脚本
<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());
});
If anyone have problem with this I found solution.如果有人对此有问题,我找到了解决方案。 U must write for each statement from scala lang.你必须为 scala lang 中的每个语句编写。 Like this:像这样:
@for(place <- places) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(@place.x
, @place.y),
map: map
});
}
And it works!它有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.