2016-04-04 16 views
2

ajaxが成功した場合、Googleマップは読み込まれません。データベーステーブルは20秒ごとに更新され、ajaxメソッドは30秒ごとにそれを読み取ります。 ajaxメソッドが正しく動作しています。コンソール上の応答を示します。マップdivがロードされていますが、マップがロードされていません。助けてください。Googleマップが読み込まれていません

Ajaxコールページ。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> </script> 
<script src="http://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=geometry"></script> 

<div id="map" style="height:500px;width:100%;" ></div> 

<script> 
var response; 
var ajax_call = function() { 
    $.ajax({          
     url: 'ajaxRequest.php',       
     data: "",       
     dataType: 'json',      
     success: function(data)   
     { 
     response = data; 
     console.log(response); 
     initialize(); 
     } 
    }); 
}; 

var interval = 5000; 
setInterval(ajax_call, interval); 

var myCenter=new google.maps.LatLng(41.669578,-0.907495); 
    var marker; 
    var map; 
    var mapProp; 

    function initialize() 
    { 
     mapProp = { 
      center:myCenter, 
      zoom:15, 
      mapTypeId:google.maps.MapTypeId.ROADMAP 
      }; 
     setInterval('mark()',5000); 
    } 

    function mark() 
    { 
     map=new google.maps.Map(document.getElementById("map"),mapProp); 
     marker=new google.maps.Marker({ 
      position:new google.maps.LatLng(response) 
      }); 
      marker.setMap(map); 
      map.setCenter(new google.maps.LatLng(response)); 
      marker.setAnimation(google.maps.Animation.BOUNCE); 
    } 
    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 

これは、あなたが文字列ではなく、オブジェクトまたは配列をコードするJSONている

<?php 
include "db_connect.php"; 
$sql="SELECT * FROM temperature_details ORDER BY id DESC LIMIT 1 "; 
$result=mysql_query($sql); 

$firstrow = mysql_fetch_assoc($result); 
$outPut = $firstrow['latitude'].','. $firstrow['longitude']; 
echo json_encode($outPut); 
?> 
+0

問題を示す[最小、完全、テスト済み、読み取り可能な例](http://stackoverflow.com/help/mcve)を入力してください(投稿されたコードの地図が表示されます。サイズのある親要素はありますか?) – geocodezip

+0

あり地図のサイズがあります – Hirantha

答えて

1

ajaxRequest.phpページです。 LatLngはあなたの文字列で何をすべきか分かりません。

試してみてください。あなたのphpのため

<?php 
include "db_connect.php"; 
$sql="SELECT * FROM temperature_details ORDER BY id DESC LIMIT 1 "; 
$result=mysql_query($sql); 
$firstrow = mysql_fetch_assoc($result); 
$outPut = array($firstrow['latitude'], $firstrow['longitude']); 
echo json_encode($outPut); 
?> 

google.maps.LatLng(response[0], response[1]) 

の代わり:あなたのJavaScriptで

google.maps.LatLng(response) 

関連する問題