第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 json_encode 將數(shù)據(jù)從 php 傳輸?shù)?javascript

使用 json_encode 將數(shù)據(jù)從 php 傳輸?shù)?javascript

PHP
回首憶惘然 2021-11-26 19:20:52
我正在構(gòu)建一個(gè) Google 地圖頁面,該頁面使用經(jīng)緯度數(shù)據(jù)坐標(biāo)來創(chuàng)建熱圖以顯示某個(gè)地區(qū)狐貍的繁殖情況。就目前而言,當(dāng) lat long 值get_points像這樣硬編碼到我的 index.php 上的JavaScript 函數(shù)中時(shí),我的應(yīng)用程序運(yùn)行良好。index.php(注意:此代碼經(jīng)測(cè)試有效,但需要谷歌地圖 api 密鑰才能加載地圖和熱圖點(diǎn))<?php require_once("resources/config.php"); ?><!DOCTYPE html><html> <head>   <title>Heatmaps</title>   <meta name="viewport" content="initial-scale=1.0, user-scalable=no">    <meta charset="utf-8">   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">   <link rel="stylesheet" href="css/style.css">   <style>     /* NOTE - GOOGLE MAPS NEED HTTPS (SECURE ORIGIN) OR IT WILL NOT SHOW A MAP. IT WILL CATEGORICALLY NOT WORK ON HTTP*/     #map {       /*height: 425px;*/       height: 100%;      }     /* Optional: Makes the sample page fill the window. */     html, body {       height: 100%;       margin: 0;       padding: 0;     }     #floating-panel {       position: absolute;       bottom: 10px;       /*left: 25%;*/       z-index: 5;       background-color: #fff;       padding: 5px;       border: 1px solid #999;       text-align: center;       font-family: 'Roboto','sans-serif';       line-height: 30px;       padding-left: 10px;     }     #floating-panel {       background-color: #fff;       border: 1px solid #999;       /*left: 25%;*/       left: 6%;       padding: 5px;       position: absolute;       /*top: 10px;*/       z-index: 5;     }問題是,我不想在我的get_points()函數(shù)中硬編碼經(jīng)緯度坐標(biāo)。我很麻煩MySQL使用我設(shè)計(jì)的使用 json_encode 的 php 函數(shù)將這些經(jīng)緯度點(diǎn)從我的表提供到上述函數(shù)。我收到的錯(cuò)誤主要是“不是有效的 MVC 數(shù)組”。但奇怪的是,我可以打印出數(shù)組。我的表架構(gòu)
查看完整描述

1 回答

?
墨色風(fēng)雨

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊

JSON 是一種數(shù)據(jù)交換格式,而不是一種編程語言。當(dāng)您在字符串中包含諸如“new google.maps.LatLng...”之類的內(nèi)容時(shí),就是這樣:一個(gè)字符串。它沒有任何意義——即使有,您的 PHP 代碼也不會(huì)返回任何內(nèi)容,您的 JavaScript 代碼也不會(huì)執(zhí)行任何內(nèi)容。


不過,您走在正確的軌道上,所以讓我們做一些小改動(dòng)。


在你的 PHP 中,你可以這樣做:


<?php


function get_coordinates() {

    $hotpointquery = query("SELECT `locationLatitude`, `locationLongitude` FROM `location_values` ");

    confirm($hotpointquery);

    while ($row = fetch_array($hotpointquery)) {

        $coordinates = [$row['locationLatitude'], $row['locationLongitude']];

    }

    return json_encode($coordinates);

}

在頁面的后面,在<script>元素中,您可以讓 PHP 打印出該數(shù)組,然后 JS 可以使用map函數(shù)將其操作為您要查找的對(duì)象:


function getPoints() {

   var coords = <?= get_coordinates() ?>

   var points = coords.map(function(coord) {

       return new google.maps.LatLng(coord[0], coord[1]);

    });

    return points;

}


查看完整回答
反對(duì) 回復(fù) 2021-11-26
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)