Okay, thanks everyone – the PHP solution works great!
So here is a guide for Jason or anyone else who stumbles across this;

1.) Make a new PHP file with the following code:

<?php

   $filename = "/usr/www/httpdocs/tiles/" . intval($_GET['z']) . "_" .
intval($_GET['x']) . "_" . intval($_GET['y']) . ".png";

   header("Content-Type: image/png");
   header("Cache-Control: max-age=84600");

   if (file_exists($filename)) {
       header("Content-Length: " . filesize($filename));
       readfile($filename);
   } else {
       readfile("/usr/www/httpdocs/clear.png");
   }

?>

Basically this PHP script will check to see if the file exists. If it
does it will return the file. If it doesn't, it will return a 1px
empty image, in this case called 'clear.png'. The only stuff you
should need to change are the paths to clear.png and $filename. Be
aware that PHP safe mode can probably screw this up.

NOTE: counter-intuitively, PHP looks for the true file destination NOT
the URL. So you need to know your servers C:// style path to the file.
There are ways around it using fopen() but you would need to look
those up - not realising this gave me headaches.

2.) Now, go into your map javascript and point to the PHP file instead
of the image URL. Specify the zoom/x/y co-ords which we will detect
using $_GET in our PHP script. If you don’t know what $_GET is have a
look on google as its quite fundamental – but in basic terms you send
variables and their values to a PHP document by appending the URL with
the format “map.html/?var=value&othervar=value”. PHP then plucks those
values and variables out for you to use.

So, using the above example:

  function createImageMapType(id) {
    return new google.maps.ImageMapType({
      getTileUrl: function(coord, zoom) {
            return "/tilefinder.php?z=" + zoom + "&x=" + coord.x + "&y=" +
coord.y;
      },
      tileSize: new google.maps.Size(256, 256),
      isPng: true,
          opacity: true
    });
  }

I hope this helps. So far it seems to be working well on my site,
there is a noticable improvement in load times and my Google PageSpeed
score got pushed up by about 20-30 points. If you want to improve
things further, I suggest setting a higher max-age (probably of 28
days/2419200) and also adding a last modified content-type header.


On Jul 30, 12:52 am, John Coryat <cor...@gmail.com> wrote:
> On Friday, July 29, 2011 6:20:03 PM UTC-5, Jason wrote:
>
> > Sorry for the noob question but does this require any other
> > configuration changes (ie. htaccess)? I've included this in my
> > index.html and it is still showing 404 errors in Chrome.
>
> > Thanks
>
> You'll have to be more specific. What did you try? What's the URL of your
> map?
>
> -John Coryat

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to