Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google Maps API V3中的PHP_Php_Google Maps_Google Maps Api 3 - Fatal编程技术网

Google Maps API V3中的PHP

Google Maps API V3中的PHP,php,google-maps,google-maps-api-3,Php,Google Maps,Google Maps Api 3,我在谷歌地图API上遇到了一个令人费解的小问题,这让我毛骨悚然。下面的代码 <?php $anim='images/animation.gif'; session_start(); if ($_SESSION['anim']==1) { $anim='images/transparent.png'; } //Select database require_once('../Connections/MySQL_extranet.php'); mysql_select_db($databas

我在谷歌地图API上遇到了一个令人费解的小问题,这让我毛骨悚然。下面的代码

<?php
$anim='images/animation.gif';
session_start();
if ($_SESSION['anim']==1) {
$anim='images/transparent.png';
}

//Select database
require_once('../Connections/MySQL_extranet.php');
mysql_select_db($database_MySQL_extranet, $MySQL_extranet);

// Get the hid which is passed from previous page
if (isset($_REQUEST['hid'])) {
    $hid=$_REQUEST['hid'];
}

//MySQL query to select location details
$query_location = "SELECT hotel, lat, lng, zoomair, sp_lat, sp_lng FROM ex_hotel WHERE hid = '$hid'";
$location = mysql_query($query_location, $MySQL_extranet) or die(mysql_error());
$row_location = mysql_fetch_assoc($location);

//Set the session variable to pass the hotel name
$_SESSION['hotel'] = $row_location['hotel'];
?>

<!DOCTYPE html>
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if (gt IE 7)|!(IE)]><!--> <html> <!--<![endif]-->
<!--Dump the above when IE7 users go below 2% -->
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Little Hotels - Directions to <?php echo $row_location['hotel'];?></title>
<meta name="description" content="Little Hotels provides accurate directions to hotels from any starting point you choose.">
<meta name="keywords" content="hotel directions, google maps, Little Hotels, driving directions, directions to <?php echo $row_location['hotel'];?>">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" >
<?php 
$full_url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$canonical_url = strtok($full_url,'?');
echo '<link rel="canonical" href="' . $canonical_url . '" >'; 
?>
<link rel="stylesheet" href="css/littlehotels.css" type="text/css">
<style type="text/css">
#content{padding: 70px 5px 0; width: 100%;}
#mapcontainer{float:left; display:block;}
#mapCanvas {width: 600px; height: 400px;}

#markerStatus {height: 0px;}
#info {height: 0px;}
#infoPanel {margin-left: 620px; margin-right:10px; display:block;}
#infoPanel div {margin-bottom: 5px;}
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
    var lat = <?php echo $row_location['lat'];?>;
    var lng = <?php echo $row_location['lng'];?>;
    var latlng = new google.maps.LatLng(lat, lng);

function geocodePosition(pos) {
  geocoder.geocode({
    latLng: pos
  }, function(responses) {
    if (responses && responses.length > 0) {
      updateMarkerAddress(responses[0].formatted_address);
    } else {
      updateMarkerAddress('Cannot determine address at this location.');
    }
  });
}

function updateMarkerStatus(str) {
  document.getElementById('markerStatus').innerHTML = str;
}

function updateMarkerPosition(startpoint) {
  document.getElementById('info').innerHTML = [
    startpoint.lat(),
    startpoint.lng()
  ].join(', ');
  }

function nextPage() {
  saddress = document.getElementById('info').innerHTML;
location='directions_detail.php?saddr='+saddress+'&daddr='+latlng;
}

function updateMarkerAddress(str) {
  document.getElementById('address').innerHTML = str;
}

function initialize() {
    var zoom = <?php echo $row_location['zoomair'];?>;
    var sp_lat = <?php echo $row_location['sp_lat'];?>;
    var sp_lng = <?php echo $row_location['sp_lng'];?>;
    var startpoint = new google.maps.LatLng(sp_lat, sp_lng);

    var map = new google.maps.Map(document.getElementById('mapCanvas'), {
    zoom: zoom,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    streetViewControl: false,
    zoomControl: true,
    zoomControlOptions: {
    style: google.maps.ZoomControlStyle.SMALL
    }
  });

var destimage = new google.maps.MarkerImage('/images/hotel_icon.gif',
      new google.maps.Size(32, 37),
      new google.maps.Point(0,0),
      new google.maps.Point(16, 35));
var destshadow = new google.maps.MarkerImage('/images/hotelshadow.png',
      new google.maps.Size(51, 37),
      new google.maps.Point(0,0),
      new google.maps.Point(16, 35));
var marker = new google.maps.Marker({
  icon: destimage,
  shadow: destshadow,
  map: map,
  position: latlng
});

var startimage = new google.maps.MarkerImage(
  '/images/start_icon.png',
      new google.maps.Size(59, 37),
      new google.maps.Point(0,0),
      new google.maps.Point(29, 35));
    var marker = new google.maps.Marker({
    position: startpoint,
    title: 'If necessary, drag this to a different start point',
    map: map,
    draggable: true,
    icon: startimage
  });

  // Update current position info.
  updateMarkerPosition(startpoint);
  geocodePosition(startpoint);

  // Add dragging event listeners.
  google.maps.event.addListener(marker, 'dragstart', function() {
    updateMarkerAddress('Dragging...');
  });

  google.maps.event.addListener(marker, 'drag', function() {
    updateMarkerStatus('Dragging...');
    updateMarkerPosition(marker.getPosition());
  });

  google.maps.event.addListener(marker, 'dragend', function() {
    updateMarkerStatus('Drag ended');
    geocodePosition(marker.getPosition());
  });
}

// Onload handler to fire off the app.
google.maps.event.addDomListener(window, 'load', initialize);
</script>
  </head>
  <body onload="initialize()">
<div id="wrapper">
<a href="http://www.littlehotels.co.uk"><img src="images/transparent.png" width="266" height="122" border="0" alt="Little Hotels"></a>
<img src="<?php echo $anim ?>" alt="Little Hotels logo" width="93" height="117" align="top">
<img src="images/header/directions.png" alt="Little Hotels" width="364" height="88">
<div id="container">
<?php include("includes/topnavbar.html"); ?>
<div id="breadcrumb">
<div class="bc-link" style="width:200px"><a href="../carhire.php" target="_blank">Car Hire at competitive rates</a></div>
<div class="bc-link"><a href="flights.php" target="_blank">Flights</a></div>
<div class="bc-link"><a href="ferries.php" target="_blank">Ferries</a></div>
<div class="bc-link"><a href="airportparking.php" target="_blank">Airport Parking</a></div>
<div class="bc-link"><a href="airporthotels.php" target="_blank">Airport Hotels</a></div>
<div class="bc-link" style="width:200px"><a href="travelinsurance.php" target="_blank">Travel Insurance</a></div>
<div class="bc-link" style="width:200px" align="right"><a href="wp/" target="_blank">News and Special Offers</a></div>
</div>
  <div id="content">
<div id="mapcontainer">
<table border=1 bordercolor="#666666">
      <tr>
        <td>
  <div id="mapCanvas"></div>
        </td>
      </tr>
</table>
</div>
<div id="infoPanel">
<h2>Driving Directions to <?php echo $row_location['hotel'];?> </h2>
<!-- Following two lines must be kept in, even though not visible. Also corresponding lines in Style -->
    <div id="markerStatus" style="visibility:hidden;"><i>Click and drag the marker.</i></div>
    <div id="info" style="visibility:hidden;"></div>
    <b>Start Point:</b>
    <div id="address"></div>
    <br><b>Destination:</b><br>
    <div><?php echo $row_location['hotel'];?></div>
<br>
To select a different starting point, just drag the start icon to the required location (zoom in if necessary for better precision).<br>
<br>
<button onclick="nextPage()">Get Directions</button>
<br>
<span class="verdana"><br>

</span>
</div>
</div>
</div>
</div>
</body>
</html>
<?php 
$_SESSION['anim']=1;
?>

小酒店-通往

我猜您正在从
$row_location['hotel']
输出一个字符串。在这种情况下,您需要用引号括起来,告诉javascript它不是一个变量,而是一个字符串值

因此:

var hotelname=“”;
要检查上述假设是否正确,请检查控制台,您将看到以下错误:

ReferenceError: <value returned by $raw_location['hotel']> is not defined
ReferenceError:未定义

像这样的函数可以将变量传递给JS,它可以防止PHP解释器抱怨任何缺少索引的情况,以防万一(这取决于PHP.ini中如何设置错误报告),例如:

var hotelname = "<?php echo(isset($row_location['hotel']) ? $row_location['hotel'] :''); ?>";
console.info(hotelname);
var hotelname=“”;
控制台信息(hotelname);
周围的引号是不同的,比如这个$row_位置['hotel']在JavaScript中被转换成字符串

。。。这段代码返回了什么,你甚至得到了什么结果

while ($row_location = mysql_fetch_assoc($location)) {
   echo '<pre>'.print_r($row_location,true).'</pre>';
}
while($row\u location=mysql\u fetch\u assoc($location)){
回显“”。打印($row\u location,true)。“”;
}

可能是JavaScript语法错误。检查控制台。
$row\u location['hotel']
的值是多少?您的代码中有一个SQL注入错误:
$query\u location=“选择酒店、lat、lng、zoomair、sp\u lat、sp\u lng FROM ex\u hotel,其中hid='hid'var hotelname = "<?php echo(isset($row_location['hotel']) ? $row_location['hotel'] :''); ?>";
console.info(hotelname);
while ($row_location = mysql_fetch_assoc($location)) {
   echo '<pre>'.print_r($row_location,true).'</pre>';
}