我不想使用任何包。 我想使用Ajax請求從數據庫中獲取GPS位置到進入谷歌地圖,但有幾個問題 1.這是我的樹枝地圖腳本使用控制器在symfony2中從數據庫獲取gps位置
<script>
function int()
{
var myLatlng = new google.maps.LatLng(49.47143, 11.107489999999984);
var mapOptions = {
zoom: 8,
center: myLatlng
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker;
$.ajax({
type: "GET",
url: "{{ path('home_page') }}",
data: "addr="+encodeURI("{{ location.address }}, {{ location.contacts }}, {{ location.managerName }}"),
success: function(data) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lat, data.longi),
map: map,
title: 'test'
});
}
});
}
google.maps.event.addDomListener(window, 'load', init);
</script>
這是從服務器端獲取GPS位置控制器
公共功能的indexAction(請求$請求) {
$ EM = $這 - > getDoctrine() - > getEntityManager();
$ resultsee = $ em-> createQuery('select a.lat,a.longi,a.managerName,a.address,a.contacts from AdminBundle:location a'); $ entities = $ resultsee-> getResult();
return new JsonResponse(array('location'=> $ entities));
最後這是錯誤我得到,而不是顯示在地圖上
{ 「位置」:[{ 「LAT」: 「13.459326003707657」, 「茇」: 「 - 16.580506139062436」, 「managerName」: 「拉明大號詹納」, 「地址」: 「班珠爾」, 「接觸」: 「3930050」}]}
}
的getResult()返回一個數組,我認爲你需要要麼使用getSingleResult()或返回第一個數組元素在你的JSON響應中。 –
我不認爲這是問題,即使當我使用這個 返回新的JsonResponse(array('location'=> $ entities [0])); 是一回事 –