• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Trying to set G-map GSM marker from a database query

I am trying to set G-map GSM marker from a database query.

$result = mysql_query("Select Street, City, State, Zip from tblOffice");

while ($row = mysql_fetch_assoc($result)) {
      echo "$x->setMarker(\"" . $row['Street'] . " " . $row['City'] . " " . $row['State'] . " " . $row['Zip'] . "\", 'red', '');\n";
}

Error Msg: Notice: Undefined property: GSM::$setMarker in ...

Thanks,
Jeff
0
Jeff
Asked:
Jeff
  • 5
  • 4
2 Solutions
 
FrozeniceCommented:
means, you are calling a function from a class that does not exists..


you need to instantiate $x where setMarker function belongs...


class Classname {
 public function setMarker() {
  return value;
 }
}

the above code can call via
$x = new classname();
$x->setMarker();

if your "setMarker" function belongs in the same class where your sql quer is
you can simple use self::setMarker

maybe try visit this link for further info
http://php.net/manual/en/language.oop5.php


hope that helps...


br
0
 
Ray PaseurCommented:
Try this:

echo "<pre>";
var_dump($x); // PRINT OUT THE GSM object.

You can post the output in the code snippet, then we can see what might be wrong with  the object.
0
 
JeffAuthor Commented:
I figured out one problem. I didn't have a "\" in front of the $x->.

It is now printing the $x-> var to the screen and not inserting it into the function.

http://www.tylerwebdesign.com/examples/google_map.php
// MAKE A GOOGLE STATIC MAP OBJECT AND TEST IT OUT
$x = new GSM;

$x->clearMarkers();
$x->setZoom();
$x->setWidth(500);
$x->setHeight(400);
$x->setCenter();

while ($row = mysql_fetch_assoc($result)) {
	echo "\$x->setMarker(\"" . $row['Street'] . " " . $row['City'] . " " . $row['State'] . " " . $row['Zip'] . "\", 'red', '');\n";
}

echo $x->asIMG();

// SHOW THE OBJECT
echo "<pre>" . PHP_EOL;
print_rr($x);
echo"</pre>" . PHP_EOL;
?>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Ray PaseurCommented:
Let me try this again...

You can post the output in the code snippet, then we can see what might be wrong with  the object.

No offense meant at all, but looking at code that does not work is really a waste of time.  Looking at the data, and taking some iterative steps to visualize the data as we change and test the code is the way professionals work.  This article may show something of the flavor of what I am getting at when I say, "Show me the data."
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7830-A-Quick-Tour-of-Test-Driven-Development.html
0
 
JeffAuthor Commented:
Not sure where to put the var dump. I hope this is what you need.

Without Var Dump it prints this to screen:
$x->setMarker("811 S.Central Expressway Suite 300G Richardson TX 75080", 'red', '');$x->setMarker("6119 Greenville Ave # 192 Dallas TX 75206", 'red', '');$x->setMarker("1084 County RD 3480 Hawkians TX 75765", 'red', '');

With Var Dump it prints this to screen:
$x->setMarker("811 S.Central Expressway Suite 300G Richardson TX 75080", 'red', '');$x->setMarker("6119 Greenville Ave # 192 Dallas TX 75206", 'red', '');$x->setMarker("1084 County RD 3480 Hawkians TX 75765", 'red', '');object(GSM)#1 (16) {
  ["center:protected"]=>
  NULL
  ["markers:protected"]=>
  array(0) {
  }
  ["default_icon:protected"]=>
  string(54) "http://maps.google.com/mapfiles/ms/micons/question.png"
  ["maptype:protected"]=>
  string(7) "roadmap"
  ["width:protected"]=>
  int(500)
  ["height:protected"]=>
  int(400)
  ["zoom:protected"]=>
  NULL
  ["format:protected"]=>
  string(3) "png"
  ["alt:protected"]=>
  bool(false)
  ["title:protected"]=>
  bool(true)
  ["class:protected"]=>
  bool(false)
  ["id:protected"]=>
  bool(false)
  ["usemap:protected"]=>
  bool(false)
  ["sensor:protected"]=>
  bool(false)
  ["url:protected"]=>
  bool(false)
  ["img:private"]=>
  string(158) "
0
 
JeffAuthor Commented:
Looks like an awesome article. I read the first paragraph and got this big lump in my throat! Yep, that's me. So what do I do? Run down to the book store and buy "Apple Pies for Dummies"! Problem is it just doesn't taste as good.

I will print it out and start reading. Have you published any programming books?
0
 
JeffAuthor Commented:
When I hard code the addresses it prints this:

object(GSM)#1 (16) {
  ["center:protected"]=>
  NULL
  ["markers:protected"]=>
  array(3) {
    [0]=>
    array(4) {
      ["color"]=>
      string(3) "red"
      ["label"]=>
      string(0) ""
      ["geocode"]=>
      string(55) "811 S.Central Expressway Suite 300G Richardson TX 75080"
      ["icon"]=>
      bool(false)
    }
    [1]=>
    array(4) {
      ["color"]=>
      string(3) "red"
      ["label"]=>
      string(0) ""
      ["geocode"]=>
      string(41) "6119 Greenville Ave # 192 Dallas TX 75206"
      ["icon"]=>
      bool(false)
    }
    [2]=>
    array(4) {
      ["color"]=>
      string(3) "red"
      ["label"]=>
      string(0) ""
      ["geocode"]=>
      string(37) "1084 County RD 3480 Hawkians TX 75765"
      ["icon"]=>
      bool(false)
    }
  }
  ["default_icon:protected"]=>
  string(54) "http://maps.google.com/mapfiles/ms/micons/question.png"
  ["maptype:protected"]=>
  string(7) "roadmap"
  ["width:protected"]=>
  int(500)
  ["height:protected"]=>
  int(400)
  ["zoom:protected"]=>
  NULL
  ["format:protected"]=>
  string(3) "png"
  ["alt:protected"]=>
  bool(false)
  ["title:protected"]=>
  bool(true)
  ["class:protected"]=>
  bool(false)
  ["id:protected"]=>
  bool(false)
  ["usemap:protected"]=>
  bool(false)
  ["sensor:protected"]=>
  bool(false)
  ["url:protected"]=>
  bool(false)
  ["img:private"]=>
  string(369) ""
}
0
 
Ray PaseurCommented:
Note this part near the bottom of the var_dump() output.
["img:private"]=>
  string(369) ""

You will need to use "view source" to see what is actually in that variable.  More to follow...
0
 
Ray PaseurCommented:
Check this.   The moving parts start around line 240.  Note that I had to urlencode the addresses.  That is a design flaw in the class - I will fix that in the EE article shortly.

If you're able to draw the map with these static addresses, your next task will be to get the variables from the data base and assign them as shown here.

HTH, ~Ray

PS: No, I have not written any books on programming, at least no yet!
<?php // RAY_google_static_map_class.php
error_reporting(E_ALL);

// DEMONSTRATE HOW TO USE THE GOOGLE MAPS API
// FOR A STATIC MAP OF SPECIFIC SIZE
// OPTIONAL CENTERED PUSHPIN
// OPTIONAL OTHER PUSHPIN(S) OR ICONS
// MAN PAGE: http://code.google.com/apis/maps/documentation/staticmaps/

// DEFINE THE GOOGLE STATIC MAPPING CLASS
class GSM
{
    // THE MAP CENTER GEOCODE, ADDRESS OR LANDMARK
    protected $center;

    // MARKER DATA ARRAY
    protected $markers;
    protected $default_icon;

    // OUR VARIABLES FOR THE MAP DISPLAY
    protected $maptype;
    protected $width;
    protected $height;
    protected $zoom;
    protected $format;

    // OUR VARIABLES FOR THE GOOGLE URL AND IMAGE TAG
    protected $alt;
    protected $title;
    protected $class;
    protected $id;
    protected $usemap;
    protected $sensor;
    protected $url;
    private $img;

    // A CONSTRUCTOR TO SET THE DEFAULT VALUES
    public function __construct()
    {
        // THE URL AND IMG TAG PARAMETERS
        $this->alt    = FALSE;
        $this->class  = FALSE;
        $this->id     = FALSE;
        $this->usemap = FALSE;
        $this->sensor = FALSE;
        $this->title  = TRUE;
        $this->url    = '';
        $this->img    = '';

        // THE CENTER AND ZOOM SCALE OF THE MAP (IF OMITTED, GOOGLE WILL CALCULATE)
        $this->center  = NULL;
        $this->zoom    = NULL;

        // THE CHARACTERISTICS OF THE MAP IMAGE
        $this->maptype = 'hybrid';    // CHOOSE
        $this->maptype = 'terrain';   // AMONG
        $this->maptype = 'satellite'; // THESE
        $this->maptype = 'roadmap';   // OPTIONS
        $this->width   = '640';
        $this->height  = '640';
        $this->format  = 'png';

        // THE DEFAULT ICON
        $this->default_icon = 'http://maps.google.com/mapfiles/ms/micons/question.png';

        // AN ARRAY OF MARKER ARRAYS
        $this->clearMarkers();

    } // END CONSTRUCTOR

    // A METHOD TO CLEAR THE MARKERS
    public function clearMarkers()
    {
        $this->markers = array();
    }

    // A SETTER TO ADD MARKERS TO THE MAP
    public function setMarker($geocode, $color='blue', $label='X')
    {
        $this->markers[]
        = array
        ( 'color'   => $color
        , 'label'   => $label
        , 'geocode' => $geocode
        , 'icon'    => FALSE
        )
        ;
    }

    // A SETTER TO ADD ICONS TO THE MAP - VIEW SOURCE HERE: http://www.visual-case.it/cgi-bin/vc/GMapsIcons.pl
    public function setIcon($geocode, $icon=FALSE)
    {
        if (!$icon) $icon = $this->default_icon;
        $this->markers[]
        = array
        ( 'color'   => FALSE
        , 'label'   => FALSE
        , 'geocode' => $geocode
        , 'icon'    => $icon
        )
        ;
    }

    // A SETTER TO OVERRIDE EACH OF THE DEFAULT VALUES
    public function setCenter($geocode=NULL)
    {
        $this->center = $geocode;
    }
    public function setMaptype($x)
    {
        $this->maptype = $x;
    }
    public function setFormat($x)
    {
        $this->format = $x;
    }
    public function setWidth($x)
    {
        $this->width = $x;
    }
    public function setHeight($x)
    {
        $this->height = $x;
    }
    public function setZoom($x=NULL)
    {
        $this->zoom = $x;
    }
    public function setAlt($x=FALSE)
    {
        $this->alt = $x;
    }
    public function setTitle($x=TRUE)
    {
        $this->title = $x;
    }
    public function setClass($x=FALSE)
    {
        $this->class = $x;
    }
    public function setId($x=FALSE)
    {
        $this->id = $x;
    }
    public function setUsemap($x=FALSE)
    {
        $this->usemap = $x;
    }
    public function setSensor($x=FALSE)
    {
        $this->sensor = $x;
    }

    // A METHOD TO PREPARE AND RETRIEVE THE MAPPING URL
    public function asURL()
    {
        $s = 'false'; // SEE http://code.google.com/apis/maps/documentation/staticmaps/#Sensor
        if ($this->sensor) $s = 'true';

        // IF ICONS OR MARKERS ARE ON THE MAP, 'IMPLODE' THE DATA INTO THE URL
        $marker_string = '';
        foreach ($this->markers as $marker)
        {
            // PROCESS FOR CUSTOM ICONS
            if ($marker['icon'])
            {
                $marker_string
                = $marker_string
                . '&markers='
                . 'icon:'
                . urlencode($marker['icon'])
                . '|'
                . $marker['geocode']
                ;
                continue;
            }
            // PROCESS FOR STANDARD MARKERS
            $marker_string
            = $marker_string
            . '&markers='
            . 'color:'
            . $marker['color']
            . '|'
            . 'label:'
            . $marker['label']
            . '|'
            . $marker['geocode']
            ;
        }

        // SET CENTER AND ZOOM, IF PRESENT
        $c = '';
        if ($this->center) $c = "&center=$this->center";
        $z = '';
        if ($this->zoom)   $z = "&zoom=$this->zoom";

        // MAKE THE URL
        $this->url
        = "http://maps.google.com/maps/api/staticmap?sensor=$s"
        . $c
        . $z
        . "&size=$this->width" . 'x' . "$this->height"
        . "&format=$this->format"
        . "&maptype=$this->maptype"
        . "$marker_string"
        ;
        return $this->url;
    }

    // A METHOD TO PREPARE AND RETRIEVE THE HTML IMAGE TAG
    public function asIMG()
    {
        // GET THE URL
        if (!$this->url) $this->url = $this->asURL();

        // GET THE ALT TEXT
        $a = "$this->maptype" . ' centered ' . "$this->center";
        if ($this->alt !== FALSE) $a = $this->alt;

        // REQUIRED FIELDS
        $this->img = '<img src="' . $this->url . '" alt="' . $a . '"';

        // OPTIONAL FIELDS - PROVIDE A DEFAULT TITLE
        $t = "$this->maptype" . ' centered ' . "$this->center";
        if     ($this->title  === TRUE ) { $this->img .= ' title="' . $t .           '"'; }
        elseif ($this->title !== FALSE)  { $this->img .= ' title="' . $this->title . '"'; }

        // OPTIONAL FIELDS MAY BE OMITTED
        if ($this->class  !== FALSE) { $this->img .= ' class="'  . $this->class  . '"'; }
        if ($this->id     !== FALSE) { $this->img .= ' id="'     . $this->id     . '"'; }
        if ($this->usemap !== FALSE) { $this->img .= ' usemap="' . $this->usemap . '"'; }

        // CLOSE THE IMAGE TAG AND CLEAR THE CONSUMED URL
        $this->img .= ' />';
        $this->url = FALSE;
        return $this->img;
    }
} // END CLASS



// MAKE A GOOGLE STATIC MAP OBJECT AND TEST IT OUT
$x = new GSM;
$x->setWidth(620);
$x->setHeight(620);
$x->setZoom(8);


// SOME OF THE THINGS WE WANT TO MAP
$center     = urlencode("Canton, TX");
$richardson = urlencode("811 S.Central Expressway Suite 300G Richardson TX 75080");
$dallas     = urlencode("6119 Greenville Ave # 192 Dallas TX 75206");
$hawkins    = urlencode("1084 County RD 3480 Hawkians TX 75765");

// ADD A CENTER POINT
$x->setCenter( $center );

// ADD SOME MARKERS
$x->setMarker( $richardson, 'red', 'R');
$x->setMarker( $dallas,     'red', 'D');

// THIS ONE MIGHT NOT WORK - SPELLING OF 'HAWKINS'
$x->setMarker( $hawkins,    'blue', 'H');

// BUT THIS VERSION MIGHT WORK, USING AN EXPLICIT GEOCODE
// SEE http://maps.google.com/maps?q=1084+County+Road+3480,+Hawkins,+Wood,+Texas+75765&hl=en&ll=32.630123,-95.221252&spn=1.695434,3.56781&sll=37.0625,-95.677068&sspn=50.557552,114.169922&vpsrc=6&geocode=FV3n8QEdaQhT-g&hnear=1084+County+Road+3480,+Hawkins,+Wood,+Texas+75765&t=m&z=9
$x->setMarker("32.630123,-95.221252", 'green', 'H');

// ECHO THE <img /> TAG INTO OUR HTML TO DRAW THE MAP
echo $x->asIMG();
echo PHP_EOL . '<br clear="all" />';

// SHOW THE OBJECT
echo "<pre>" . PHP_EOL;
print_rr($x);
echo"</pre>" . PHP_EOL;





// UNRELATED FUNCTION TO MAKE THE OUTPUT OMIT THE PRIVATE PROPERTIES
function print_rr($thing)
{
    $str = print_r($thing, TRUE);
    $arr = explode(PHP_EOL, $str);
    $num = count($arr) - 1;
    foreach ($arr as $ptr => $txt)
    {
        if (preg_match('/:private]/', $txt))
        {
            unset($arr[$ptr]);
        }
    }
    echo implode(PHP_EOL, $arr);
}

Open in new window

0
 
JeffAuthor Commented:
Thanks to you both. I have gone a different direction.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now