-2

Maps API をランダムな座標で使用しようとしていますが、.js ファイルの JavaScript 関数に php ファイルの php 値をどのように入力すればよいかわかりません。たとえば、いくつかのコードがある場合:

1) 2 つの座標間のルートを生成する API コード (order2.js):

(function() {
window.onload = function() {
// Creating a map
var options = {
zoom: 8,
center: new google.maps.LatLng(-33.3834, -70.6),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
// Creating an array that will contain the points for the polyline
var route = [
new google.maps.LatLng(-33.02644,-71.539775),
new google.maps.LatLng(-33.605148,-70.702197)
];
// Creating the polyline object
var polyline = new google.maps.Polyline({
path: route,
strokeColor: "#ff0000",
strokeOpacity: 0.6,
strokeWeight: 5
});
// Adding the polyline to the map
polyline.setMap(map);
};
})();

2) 表示する Google Maps API コード (map2.html):

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chapter 4 - Google Maps API 3</title>
<link rel="stylesheet" href="css/graphic.css" type="text/css" media="all" />
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/order2.js"></script>
</head>
 <body>
 <input type="button" value="getValues" id="getValues" />
 <input type="button" value="changeValues" id="changeValues" />
 <div id="map"></div>
 </body>
</html>

3) 次のフロート ランダム コード (random.php) がある場合:

<?php

    while($x <= 2995 and $y <= 71333)
    {
    $x = rand(2025,2995);
    $y = rand(70116,71333);
    $w = $x/100;
    $z = $y/1000;
    echo $w."<br>".$z."<br>";    
}    

?>

コードの前に基づいて、私は本当に知る必要があります:

$w と $z の値を random.php から order2.js に関連する任意の関数 (a,b) に転送するにはどうすればよいですか?

あなたの有益な助けに感謝します。

よろしく

4

2 に答える 2

0

1)乱数を作成するためだけの場合は、JavaScriptで簡単に行うことができます。

2) php からデータを取得することが本当に重要である場合、最善の方法は、エンド ユーザーから隠されているテキストエリアを作成することです。

js ファイルに転送するすべてのデータを JSON 形式でテキストエリアに配置します。このようなもの:

<textarea id="phpData" style="display:none">{"J":5,"test2":"N"}</textarea>

jsからアクセスしたい場合:

var thePhpData = JSON.parse( $("#phpData").val() );

値を取得するには:

 thePhpData.J
 thePhpData.test2
于 2013-09-25T04:53:22.510 に答える