我是一个相当新手的网站管理员,在这里从优秀的志愿者那里得到了大量的帮助,我感谢你们所有人。
最近这里有人(戴维)帮助我获得了谷歌地图来查询数据库并显示在网页上,但它导致了我自己似乎无法破解的页面速度问题。
我来总结一下;(通过从 https 中删除 1 t 来满足此处的算法故意破坏链接)使用此 URL:
http://classifieds.your-adrenaline-fix.com/detail.php?fatherID=37&TypeID=42&ListingID=42
谷歌页面速度说;(来自我的注意:以下网址的完整外观如下:
htps://mts0.googleapis.com/vt?lyrs=h@210000000&src=apiv3&hl=en-US&x=36&y=52&z=7&s=&style=api%7Csmartmaps)
以下资源具有相同的内容,但来自不同的 URL。从一致的 URL 提供这些资源以节省 10 个请求和 1.9KiB。
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
此外,我得到了;
以下资源缺少缓存验证器。未指定缓存验证器的资源无法有效刷新。指定 Last-Modified 或 ETag 标头以启用以下资源的缓存验证:
htp://www.google.com/.../brand?...
htps://maps.googleapis.com/.../GeocodeService.Search?...
htps://maps.googleapis.com/.../StaticMapService.GetMapImage?...
htps://maps.googleapis.com/.../StaticMapService.GetMapImage?...
htps://maps.googleapis.com/maps/api/js?sensor=true
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts0.googleapis.com/vt?...
htps://mts1.googleapis.com/.../ft?...
htps://mts1.googleapis.com/.../ft?...
htps://mts1.googleapis.com/.../ft?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
htps://mts1.googleapis.com/vt?...
我希望这里有人熟悉这一点,并且可能对如何解决这些问题有所了解。
这是 detail.php 上的代码
$TypeID = isset($_GET['TypeID']) ? $_GET['TypeID'] : '';
$ListingID = isset($_GET['ListingID']) ? $_GET['ListingID'] : '';
$allowed_tables = array('tt_42', 'tt_43');
$table ="tt_".$TypeID;
$dbh = new PDO("mysql:host=$host;dbname=$db", $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
if (in_array($table, $allowed_tables)) {
$query = "SELECT `Address`, `City`, `State/Province`, `Zip/Postal`, `Country` FROM `$table` WHERE `ID` = ? AND `ExpireDate` > NOW()";
}
$stmt = $dbh->prepare($query);
$stmt->bindParam(1,$ListingID);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
$Address = $listing['Address'];
$City = $listing['City'];
$State = $listing['State/Province'];
$Zip = $listing['Zip/Postal'];
$Country = $listing['Country'];
echo '<h2>Map of Surrounding Area With Navigational Aides</h2>';
echo '<div class="CalloutBoxBlue">Hover over map and scroll, or use + and - in LH corner of map to zoom or expand viewing area. Alternatively, hold down mouse to manually move the map to a different geographical location, or drag the person icon to a specific location on the map for a street view.</div>';
echo '<div id="GoogleMap">';
echo '<iframe scrolling="no" style="width:480px; height:300px; border:0px;" frameborder="0" src="googlemap.php?Address='.$Address.'&City='.$City.'&State='.$State.'&Zip='.$Zip.'&Country='.$Country.'"></iframe>';
echo '</div>';
}
catch(PDOException $e) {
echo "Error in Displaying Google Map.". $e->getMessage() ;// Remove or modify after testing
//file_put_contents('PDOErrors.txt',date('[Y-m-d H:i:s]').", mapSelect.php, ". $e->getMessage()."\r\n", FILE_APPEND);
}
另外,这是 googlemap.php 的代码
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map { height: 100% }
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true">
var geocoder;
var map;
<?php
// Get parameters from URL
$Address = isset($_GET['Address']) ? $_GET['Address'] : '';
$City = isset($_GET['City']) ? $_GET['City'] : '';
$State = isset($_GET['State']) ? $_GET['State'] : '';
$Zip = isset($_GET['Zip']) ? $_GET['Zip'] : '';
$Country= isset($_GET['Country']) ? $_GET['Country'] : '';
//Set javascript variables
echo "var Address ='".$Address."';\n";
echo "var City ='".$City."';\n";
echo "var State ='".$State."';\n";
echo "var Zip ='".$Zip."';\n";
echo "var Country ='".$Country."';\n";
?>
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(0,0);
var mapOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
codeAddress();
}
function codeAddress() {
var address = Address+','+City+','+State+','+Zip+','+Country;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Location not acquired for the following reason: ' + status);
}
});
}
</script>
</head>
<body onload ="initialize()">
<div id="map" style="width:100%; height:100%"></div>
</body>
</html>
我不知道它是否真的 100% 相关,但我的 htaccess 中也有以下内容用于缓存资源:
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 year"
# Favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
我希望这只是需要向我的 htaccess 添加一行代码的问题。如果是这样,我不知道我会添加什么,如果有人可以帮助我,我将不胜感激。