Jump to content

Recommended Posts

Hi all ive created a script that inserts post codes from a database into a geocoder that then pinpoints the locations on the google maps api. Trouble is that it can be really slow. As i guess it has to process each postcode seperatly from another URL.

 

What i want to know is there any way for me to speed this process up as at the moment for about 10 records to be processed it takes around 13secs which will probably put any user off instantly!

 

Here is my code:

 

    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAVB6_Pid5otsy8EjejpFSmBR3B9hOBASpmCh0hnUHdY3zy_OoFxQY7sAWvr8MPMRYjIZWvTGByQJU3g"
      type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    function load() {
      if (GBrowserIsCompatible()) {
    function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
        });
        return marker;
      }
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(50.8040, -1.0700), 13);
	map.addControl(new GLargeMapControl());

$i=0;
while ($i < $num) {

$event=mysql_result($result,$i,"event");
$postcode=mysql_result($result,$i,"postcode");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");
?>
<?
$url = "http://geo.localsearchmaps.com/?zip=";
$url .= urlencode($postcode);
$url .= "&country=UK&use=google2&format=txt";

if ($grab_coordinates = file_get_contents($url)) {
$coord_pair = explode(", ", $grab_coordinates); 

if (sizeof($coord_pair) == 2) {                    

$latitude = $coord_pair[0];
$longitude = $coord_pair[1]; 
};
};
?>
<?
echo "var point = new GLatLng($latitude,$longitude);
      var marker = createMarker(point,'<div style=\"width:240px; padding:4px; font-family:Lucida Sans, Arial;\">$event</br>$postcode</br>Email: $email</br>Telephone: $phone</div>')
      map.addOverlay(marker);"
?>

<?
$i++;
}
mysql_close();
?>

 

thanks

 

 

      }

 

    }

    //]]>

    </script>

Link to comment
https://forums.phpfreaks.com/topic/85933-speeding-up-responce-time/
Share on other sites

I'd say it's a connection / response issue with goggle, but they probably know that!

I'm not sure if this is happening client side or server side, either way you could try threads to connect in parallel rather than series. I thought there was some support for threads in php but finding any ref's at mo, you could always run them through the system dumping the output and parsing that, however it seems there is support for javascript so you could use ajax...(oops this may depend upon browser design...)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.