Re: From city to lati and long [message #175029 is a reply to message #175023] |
Thu, 04 August 2011 15:27 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Wed, 03 Aug 2011 23:20:28 -0400, Jerry Stuckle wrote:
> On 8/3/2011 6:08 PM, Sarah wrote:
>> I can't find a solution :((( please help me!
>
> Ask in the right place and you'll get a good answer. This isn't a PHP
> problem (other than maybe the parameters being sent are wrong - but that
> could be in any language).
There are, though, imo, php issues with the code, and php techniques that
can be used to try and determine the problem.
eg test that location is not false, is an array and has a viable count
before handling it as an array and passing its first element to explode.
if ($location === false)
{
alert_mission_control("Houston, we have a problem! We failed to receive
a file from google maps!");
}
else if (!isarray($location))
{
alert_mission_control("Houston, we have a problem! We didn't get an
array of lines from the file received from google maps!");
}
else if (count($location) == 0))
{
alert_mission_control("Houston, we have a problem! The file of lines we
got from google maps is empty!");
}
else if (count($location) > $max_lines_in_google_maps_file))
{
alert_mission_control("Houston, we have a problem! The file of lines we
got from google maps is too big!");
}
eg use curl to retrieve the page, allowing better handling for timeouts
and errors from the remote (google maps) web server, as well as checking
of the return code such as:
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($response_code != "200")
{
alert_mission_control("Houston, we have a problem! Google maps didn't
respond with a 200 code, gave us {$response_code} instead");
}
eg use php functions to test the returned values and write details of
each request and the response received from the remote (google maps) web
server to a suitable log file if one of $stat, $acc, $latitude, or
$longitude is unexpectedly null, undefined or empty after the line:
list ($stat,$acc,$latitude,$longitude) = explode(",",$location[0]);
if ($latitude == null || $latitude = "" || floatval($latitude == 0.0))
{
alert_mission_control("Houston, we have a problem! Latitude is a weird
value '{$latitude}'. Position was '{$position}' and Location[0] was
'{$location[0]}'.");
}
if ($longitude == null || $longitude = "" || floatval($longitude == 0.0))
{
alert_mission_control("Houston, we have a problem! Longitude is a weird
value '{$longitude}'. Position was '{$position}' and Location[0] was
'{$location[0]}'.");
}
All of these, whilst not actually solving her problem, are things that
can be done in php that might improve the robustness of the code and / or
make it easier to determine what's going wrong.
For completeness:
function alert_mission_control($msg)
{
file_put_contents ("/home/<myname>/logs/something.log",
date(DATE_RFC2822) . " " . $msg . "\n",
FILE_APPEND);
}
Rgds
Denis McMahon
|
|
|