Jump to content

Google Maps code wont run on server.


twinytwo

Recommended Posts

Hi guys,

 

this is the geocoding part of the code.

 

I ran this ion my localhost and it runs ok. Then when i uploaded it to my server i got

 

500 - Internal server error.

There is a problem with the resource you are looking for, and it cannot be displayed.

 

When i take out the php the html code run ok... so its not that. Can anyone help?

 

I have taken out my key and db connection.

 

Im hosted on black knight if thats any help

 

<?php
require("config.php");

define("MAPS_HOST", "maps.google.com");
define("KEY", "****");

// Opens a connection to a MySQL server
$connection = mysql_connect("localhost", "root", "password");
if (!$connection) {
  die("Not connected : " . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db("database", $connection);
if (!$db_selected) {
  die("Can\'t use db : " . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM users WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY;

// Iterate through the rows, geocoding each address
while ($row = @mysql_fetch_assoc($result)) {
  $geocode_pending = true;

  while ($geocode_pending) {
    $address = $row["address1"];
    $id = $row["id"];
    $request_url = $base_url . "&q=" . urlencode($address);
    $xml = simplexml_load_file($request_url) or die("url not loading");

    $status = $xml->Response->Status->code;
    if (strcmp($status, "200") == 0) {
      // Successful geocode
      $geocode_pending = false;
      $coordinates = $xml->Response->Placemark->Point->coordinates;
      $coordinatesSplit = explode(",", $coordinates);
      // Format: Longitude, Latitude, Al
  itude
      $lat = $coordinatesSplit[1];
      $lng = $coordinatesSplit[0];

      $query = sprintf("UPDATE users " .
             " SET lat = '%s', lng = '%s' " .
             " WHERE id = '%s' LIMIT 1;",
             mysql_real_escape_string($lat),
             mysql_real_escape_string($lng),
             mysql_real_escape_string($id));
      $update_result = mysql_query($query);
      if (!$update_result) {
        die("Invalid query: " . mysql_error());
      }
    } else if (strcmp($status, "620") == 0) {
      // sent geocodes too fast
      $delay += 100000;
    } else {
      // failure to geocode
      $geocode_pending = false;
      echo "Address " . $address . " failed to geocoded. ";
      echo "Received status " . $status . "
\n";
    }
    usleep($delay);
  }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Your Profile Page</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/1.css" type="text/css" media="screen,projection" />

</head>

<body>

<div id="wrapper" class="fixed">

	<div id="header">

			<h1>Find A Tag Team</strong></h1>

			<ul id="nav">

					<li><a href="home.html">Home</a></li>

					<li><a href="index.html"></a>Logout</li>

					<li><a href="Links.php">Links</a></li>

					<li><a href="Videos.php">Videos</a></li>



			</ul>

	</div>

	<div id="sidebar_left">

			<h2>Your Profile Page</h2>

			<p>


			</p>

			<p>

					From here you can ...<br />
					-Edit all your information <br />
					-Search for other users <br />
					-View any emails you may have recieved</br />

			</p>

			<p>



			</p>

	</div>




	<div id="content">

 <h1>Profile</h1>
<div class ="message"> The map has been succesfully updated. <br />
<a href = "map.php">View the Map</div>

<div id="footer">


	</div>
</div>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/257458-google-maps-code-wont-run-on-server/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.