I'm getting this error when geocoding maps on google maps when it prints the map. when there is a mistake in the address, for example a state in a city, and it is something that is hard to filter for.
11201203205207209211213215217219221
Notice: Undefined offset: 3 in /Library/WebServer/Documents/phoogle1a.php on line 265
I need to fix this error in the class or I need to trap for it so it doesn't print this on the map. The try/catch below is not working but I suspect the problem is the line in the phoogle class on 265. I need to get rid of it one way or the other. I tried turning error reporting off and that didn't work either. I would really like the $value that is the address array to be printed nicely to tell the user to fix it but not the above ugly message.
My code is:
$addr = $_POST['q'];
$addrArray= unserialize($addr);
$addrUnique = array_unique($addrArray);
if(sizeof($addrUnique)>200 )
{
echo "The maximum addresses are 200 or less at a time. You are over the limit.";
exit;
}
foreach($addrUnique as $key => $value){
try{
$map->addAddress($value);
$pointer = $map->addAddress($value);
print_r($pointer);
switch($pointer){
case(strpos($pointer,"Service Unavailable")):
throw new Exception($e="error_503");
break;
case (strpos($pointer, "Undefined offset: 3")):
throw new exception($e="undefined_offset");
break;
}
}
catch (Exception $e){
if ($e ="error_503"){
echo "Please be patient while Google is geocoding.";
sleep(6);
$map->addAddress($value);
} else if($e ="undefined_offset") {
echo "There is an error in this address:"."$value";
}
}
}
$map->printGoogleJS();
line 265 of the class is on the ****
It parses the XML addresses for google maps to print. I think it pops the string out and outputs that on the browser. It would be nice if I could fix it so it looks better.
function xml2array($xml){
$this->depth=-1;
$this->xml_parser = xml_parser_create();
xml_set_object($this->xml_parser, $this);
xml_parser_set_option ($this->xml_parser,XML_OPTION_CASE_FOLDING,0);//Don't put tags uppercase
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
xml_set_character_data_handler($this->xml_parser,"characterData");
xml_parse($this->xml_parser,$xml,true);
xml_parser_free($this->xml_parser);
return $this->arrays[0];
}
function startElement($parser, $name, $attrs){
$this->keys[]=$name;
$this->node_flag=1;
$this->depth++;
}
function characterData($parser,$data){
$key=end($this->keys);
$this->arrays[$this->depth][$key]=$data;
$this->node_flag=0;
}
function endElement($parser, $name)
{
$key=array_pop($this->keys);
if($this->node_flag==1){
$this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1];*****
unset($this->arrays[$this->depth+1]);
}
$this->node_flag=1;
$this->depth--;
}