我遇到問題,我想知道有誰能幫助我。結果我想製作一些帶有不同GPS軌跡的小地圖。但是我有一個獲取數據的問題。我需要從服務器獲取GPS跟蹤。然後提取屬於該軌道的所有點的座標,並將這些數據放入js中(在地圖上)。我會告訴: 在這裏,我有一個控制器:如何從JSP獲取數據到js
@Controller
public class TracksGeopointsController {
@Autowired
private IndexGeopointsService indexGeopointsService;
@Autowired
private TracksGeopointsService tracksGeopointsService;
@Autowired
private FileService fileService;
@Autowired
private MySaxParser mySaxParser;
@RequestMapping(value = TracksGeopointsRoutes.TRACKS, method = RequestMethod.GET)
public String tracks(Model model){
List<TracksGeopointsDoc> tracks = tracksGeopointsService.findAllTracks();
Map<ObjectId, List<DotGeopointsDoc>> dotsMap = new HashMap<ObjectId, List<DotGeopointsDoc>>();
for (TracksGeopointsDoc track : tracks){
try {
List<DotGeopointsDoc> dots = tracksGeopointsService.getAllTrackDots(track.getId());
dotsMap.put(track.getId(), dots);
model.addAttribute("dotsMap", dotsMap); //here I put data to a model to transport it to JSP
model.addAttribute("tracks", tracks); //here I put data to a model to transport it to JSP
} catch (TrackNotExistException e) {
e.printStackTrace();
}
}
Breadcrumbs breadcrumbs = indexGeopointsService.breadcrumbs();
breadcrumbs.setCurrentPageTitle("GPS треки");
model.addAttribute("breadcrumbs", breadcrumbs);
return "com.ub.geopoints_test.tracks";
}
}
我的JSP看起來像這樣:
<div class="row">
<div class="col-md-12">
<c:forEach var="track" items="${tracks}" varStatus="count"> //I know how to extract data from model above - ${tracks}
<script>
var map = L.map('map');
// create the tile layer with correct attribution
var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 1, maxZoom: 12, attribution: osmAttrib});
map.addLayer(osm);
L.Routing.control({
waypoints: [
L.latLng(57.74, 11.94), // here I want to put data that I gave to model. If it was not js, I'll do this: L.latLng(${dotsMap.get(track.id).lat}, ${dotsMap.get(track.id).lat}) But I don't know how can I do it with js
L.latLng(57.6792, 11.949),
L.latLng(57.65, 11.888)
]
}).addTo(map);
</script>
</c:forEach>
</div>
</div>
請,任何人都可以幫助我。我真的不知道我該怎麼做。
請清除這個問題,從'L.latLng(57.74,11.94)'這條線你需要打電話給你的控制器。我對麼? –
是的。從這一行我需要獲取我通過控制器傳遞的數據。 – Dexa
您可以通過[ajax](http://api.jquery.com/jquery.ajax/)發送您的請求並獲得回覆。 –