HTML5 と PHP の作業を開始しましたが、php ファイル内に Google マップを挿入する際に問題がありました。私が書いたサンプルコードを載せます。多分誰かが私の状況の解決策を持っています。
「index.html」である私の最初のファイルには、入力と、入力を送信してphpファイルに送信するボタンがあります。このために私が書いたコードを以下に示します。
<form action="deneme.php" method="post">
<input type="text" name="searchtxt" id="searchtxt" placeholder="Write something to search"></br>
<div align="center">
<input type="submit" name="locationbtn" data-icon= "search" data-iconpos="right" data-theme="a" data-inline="true" value="Find Location"></button>
</div>
</form>
私の「deneme.php」ファイルでは、コードはまさにそのようなものです。
<!DOCTYPE html>
<head>
<meta charset=utf-8>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<link rel="stylesheet" href="css/bgcolor.css" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript">
function TestGeo()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition( TestMap, error, {maximumAge: 30000, timeout: 10000, enableHighAccuracy: true} );
}
else
{
alert("Sorry, but it looks like your browser does not support geolocation.");
}
}
var map;
function TestMap(position)
{
// Define the coordinates as a Google Maps LatLng Object
var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Prepare the map options
var mapOptions =
{
zoom: 10,
center: coords,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Create the map, and place it in the map_canvas div
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
// Place the initial marker
var marker = new google.maps.Marker({
position: coords,
map: map,
title: "Your current location!"
});
function error() {
alert("Cannot locate user");
}
</script>
</head>
<body onload="TestGeo();">
<?php
$t=date("H");
$search=$_REQUEST['searchtxt'];
if($t<"18"){
echo ("<br/>Have a good day " . $search . " !");
}
else{
echo ("<br/>Have a good night " . $search . " !") ;
flush();
flush();
}
?>
</div>
<div id="map_canvas" style="width: 100%; height: 85%; border-right: 1px solid #666666; border-bottom: 1px solid #666666; border-top: 1px solid #666666; border-left: 1px solid #AAAAAA;" align="center">
</div>
主な問題は、[送信] ボタンをクリックしたときに deneme.php ファイルが Google マップを読み込んでいないことですが、index.html に入力された入力値が deneme.php ファイルに出力されています。<input>
これを行った後、ボタンをからに変更して問題を解決しようとしましたが<button href="#deneme.php" type="button" name="locationbtn" data-icon= "search" onclick="location.href='deneme.php'" data-iconpos="right" data-theme="a" data-inline="true">Find Location</button>
、phpファイルに印刷されたhtmlファイルの入力を取得できませんでした。ただし、この場合はGoogleマップが機能します。