Problems with phoogle.

Discussion in 'PHP' started by tonicc, Nov 10, 2008.

  1. #1
    Hi, I use phoogle in my sites and it works well, but today appear an error:

    Fatal error: Cannot use string offset as an array in /home/public_html/phoogle.php on line 132
    Code (markup):
    In the line 132:
    if (empty($results['kml'][Response]['Placemark']['Point']['coordinates'])){
    PHP:

    What's happen? Google changed something in the google maps api?

    Thankyou
     
    tonicc, Nov 10, 2008 IP
  2. DiscussNow

    DiscussNow Peon

    Messages:
    474
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Possible could be that [Response] needs to be ['Response'] ?
     
    DiscussNow, Nov 10, 2008 IP
  3. tonicc

    tonicc Well-Known Member

    Messages:
    198
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Yesterday it works... but today no..

    I tryied to put ['Response'] in all of [Response] and it doesn't works....

    Thank you
     
    tonicc, Nov 10, 2008 IP
  4. anono123

    anono123 Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I suddenly started getting this error too. (Fatal error: Cannot use string offset as an array in .... phoogle.php on line 132). I wonder if Google maps has changed its protocol. Here's a quick fix:

    Comment out the following lines of code in phoogle.php:


    $results = $this->xml2array(utf8_encode($addressData));

    if (empty($results['kml'][Response]['Placemark']['Point']['coordinates'])){
    $pointer = count($this->invalidPoints);
    $this->invalidPoints[$pointer]['lat']= $results['kml'][Response]['Placemark']['Point']['coordinates'][0];
    $this->invalidPoints[$pointer]['long']= $results['kml'][Response]['Placemark']['Point']['coordinates'][1];
    $this->invalidPoints[$pointer]['passedAddress'] = $address;
    $this->invalidPoints[$pointer]['htmlMessage'] = $htmlMessage;
    }else{
    $pointer = count($this->validPoints);
    $this->validPoints[$pointer]['lat']= $results['kml'][Response]['Placemark']['Point']['coordinates'];
    $this->validPoints[$pointer]['long']= $results['kml'][Response]['Placemark']['Point']['coordinates'];
    $this->validPoints[$pointer]['passedAddress'] = $address;
    $this->validPoints[$pointer]['htmlMessage'] = $htmlMessage;
    }

    Replace with this:

    $xml = new SimpleXMLElement(utf8_encode($addressData));
    $myCode = (string)$xml->Response->Status->code;
    $myCoordinates = (string)$xml->Response->Placemark->Point->coordinates;
    $myCoordinatesArray = explode(",", $myCoordinates);
    $pointer= '0';
    $this->validPoints[$pointer]['long']= $myCoordinatesArray[0];
    $this->validPoints[$pointer]['lat']= $myCoordinatesArray[1];
    $this->validPoints[$pointer]['passedAddress'] = $address;
    $this->validPoints[$pointer]['htmlMessage'] = $htmlMessage;


    I'm not sure how robust this solution is, but for the moment it is working for me.

    Good luck,
    Anono123
     
    anono123, Nov 11, 2008 IP
  5. tonicc

    tonicc Well-Known Member

    Messages:
    198
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    Thank you very much. It works for me :D


    Edit: It works well in http://wwhatismyip.info. But in one of my sites... only shows one result http://deconcert.info/mapa-de-concerts, i have 8 places to show... :S
     
    tonicc, Nov 11, 2008 IP
  6. Iiridayn

    Iiridayn Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Add this line <?php if(!trim($data)) return; // strips all whitespace strings ?> before the first line of function characterData(...). It strips out the whitespace which is causing the errors. Had to fix it myself.
     
    Iiridayn, Nov 11, 2008 IP
  7. tonicc

    tonicc Well-Known Member

    Messages:
    198
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #7
    Thank you, it works fine :D !
     
    tonicc, Nov 11, 2008 IP
  8. UCDaZ

    UCDaZ Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    When I make those changes you suggested, the gmap only displays one marker for a location. I'm trying to pass at least 5 locations to the map hence 5 markers should display on the gmap.
     
    UCDaZ, Nov 11, 2008 IP
  9. UCDaZ

    UCDaZ Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    I also get an error with an undefined offset at line 336. This error happens every other time I refresh the page.
    phoogle.php
    Line 332: function endElement($parser, $name)
    Line 333: {
    Line 334: $key=array_pop($this->keys);
    Line 335: if($this->node_flag==1){
    Line 336: $this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1];
    Line 337: unset($this->arrays[$this->depth+1]);
    Line 338: }
    Line 339: $this->node_flag=1;
    Line 340: $this->depth--;
    Line 341: }
     
    UCDaZ, Nov 11, 2008 IP
  10. UCDaZ

    UCDaZ Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    Ah ha!
    Got it! Just comment out the "$pointer='0' and add $pointer = count($this->validPoints);
    All the markers are displaying now!
    Nick Leung

    $xml = new SimpleXMLElement(utf8_encode($addressData));
    $myCode = (string)$xml->Response->Status->code;
    $myCoordinates = (string)$xml->Response->Placemark->Point->coordinates;
    $myCoordinatesArray = explode(",", $myCoordinates);
    //$pointer= '0';
    $pointer = count($this->validPoints);
    $this->validPoints[$pointer]['long']= $myCoordinatesArray[0];
    $this->validPoints[$pointer]['lat']= $myCoordinatesArray[1];
    $this->validPoints[$pointer]['passedAddress'] = $address;
    $this->validPoints[$pointer]['htmlMessage'] = $htmlMessage;
     
    UCDaZ, Nov 11, 2008 IP
  11. zachmb

    zachmb Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hey!

    I just wanted to let both anono and ucdaz and everyone else who has contributed to this problem that I greatly appreciate your solutions. I had worked 22 hours a day for 2 weeks alone on a project for one of my most important clients to date on dynamic website and personalized content management system in which thousands of dollars were spent, and i used a customized version of this phoogle maps script. However this google maps script was an integral part of the main section on the website, and after all of my hard work, minutes after i scheduled a meeting with the client to present the final product, the script had randomly broken and i was mortified at the fatal error outputted by this now-broken code. The worst part was I spent two whole days testing and retesting my entire project and everything worked beautifully, and the one thing that was contingent upon an outside source was the one thing that broke, and i had no control over it. However your fix provided a quick and easy solution to this problem and i was able to get the website back online, and the rest of the presentation went smoothly.

    Granted i have worked in a few of my own personal failsafes to ensure stability and that something like this never happens again, but again i just wanted to thank all of you for your help on this issue!! I really appreciate it. Sorry for the life story!

    Cheers :)
     
    zachmb, Nov 12, 2008 IP
  12. UCDaZ

    UCDaZ Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #12
    Does anyone know what caused phoogle to crash?
     
    UCDaZ, Nov 23, 2008 IP
  13. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #13
    I applied the above changes and now I receive an error:

    Notice: Trying to get property of non-object in C:\WebSite\htdocs\stripclubs\class_phoogle.php on line 134

    Notice: Undefined offset: 1 in C:\WebSite\htdocs\stripclubs\class_phoogle.php on line 139



    Line 134 is now: $myCoordinates = (string)$xml->Response->Placemark->Point->coordinates;

    Line 139 is now: $this->validPoints[$pointer]['lat']= $myCoordinatesArray[1];

    I applied both bug fixes mentioned in this thread. Still nothing is working.
     
    NetStar, Nov 29, 2008 IP
  14. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #14
    Nevermind got it working. My variables for city address etc. weren't functioning right. My error..not phoogles (after the bug fix).
     
    NetStar, Nov 29, 2008 IP
  15. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #15
    The careless person who wrote this class forgot to include zoomLevel method support in the source code but did document it's use.

    Add this code to the class to support zoomLevel

    
    /**
    * @function     zoomLevel
    * @param        $zoomLevel:int
    * @returns      nothing
    * @description  Sets the zoom level of the map to be displayed (Range: 0-17; Default: 4.)
    */
    	function zoomLevel($zoom){
    		$this->zoomLevel = $zoom;
    	}
    
    PHP:
     
    NetStar, Nov 29, 2008 IP
  16. anono123

    anono123 Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Justin Johnson, the author of Phoogle, has posted an official fix at:

    http://www.webdevkungfu.com/fix-for-phoogle

    It's the same fix posted by Iiridayn above, trimming out the white space from $data at the start of function characterData.

    I recommend that you use this official fix, rather than the quick and dirty fix I posted above ("Quick fix for phoogle fatal error, line 132") on November 11.

    Nice work, Iiridayn. And thanks, Justin.
     
    anono123, Dec 5, 2008 IP
  17. tonicc

    tonicc Well-Known Member

    Messages:
    198
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #17
    Thanks for the advise anono123 :)
     
    tonicc, Jan 6, 2009 IP