我连接到DB NOSQL在线返回JSON值
例如
{
"_id"=>"5b2e880c1de0c46b00001dda",
"gps_lattitude"=>"30.63",
"gps_longitude"=>"31.09",
"gps_speed_kph"=>"0.1",
"gps_heading"=>"129.36",
"gsm_csecond"=>58,
"gsm_second"=>46,
"gsm_minute"=>35,
"gsm_hour"=>21,
"gsm_month"=>6,
"gsm_day"=>20,
"gsm_year"=>2018,
"HWID"=>"AC37439773C8",
"pulse_rate"=>585,
"recrdID"=>458
}
需要显示gps_longitude
和gps_lattitude
到谷歌地图
使用SQL数据库时,我可以轻松做到这一点,但不知道如何使用JSON做到这一点
控制器:
body = {gps_lattitude: "40.4967628", gps_longitude: "-80.0584638"}.as_json
@lat = body["gps_lattitude"]
@long = body["gps_longitude"]
网页:
<div id="googleMap" style="width:100%;height:400px;"></div>
<script>
// Google Map Init
function initMap(){
var lat = "<%= @lat %>"; // sample - "40.4967628"
var lng = "<%= @long %>"; // sample - "-80.0584638"
var uluru = {lat: parseFloat(lat), lng: parseFloat(lng)};
var map = new google.maps.Map(document.getElementById('googleMap'), {
zoom: 15,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map
});
}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?callback=initMap"></script>