SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined variable trouble

    I'm confused as to how to get an argument from one function to another... or how to solve my issue here. When I run this, it throws a js error "marker is undefined". Anyone have any thoughts as to how I could get this loop to work? I'm trying to pass the info into the text "bubbles" that appear when you click on the marker.

    PHP Code:
    var map = null;
        var geocoder = null;
        <?php
            $key 
    0;
            foreach(
    $results as $key => $contact) {
                
    $results[$key][javavarname] = "address$key";
                
    $varString "var address$key = \"$contact[address1]$contact[city]$contact[state]$contact[zip]\";\n";
                echo 
    $varString;
                
    $key++;
            }
        
    ?>

        function markAddress(address) {
          if (geocoder) {
            geocoder.getLatLng(
              address,
              function(point) {
                if (!point) {
                // alert(address + " not found");
                } else {
                  map.setCenter(point, 7);
                  var marker = new GMarker(point);
                  map.addOverlay(marker);
                }
              }
            );
          }
        }
        
        function load() {
          if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map"));
            geocoder = new GClientGeocoder();
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            
    <?
            
    foreach($results as $contact) {
                echo 
    "markAddress(" $contact[javavarname] . ");\n";
                echo 
    "GEvent.addListener(marker, \"click\", function() {\n";
                echo 
    "marker.openInfoWindowHtml(" $contact[javavarname] . ");\n";
                echo 
    "});\n";
            }
    ?>
          }
        }

  2. #2
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, now I changed it to use global variables, but it throws an error "'__e_' is null or not an object. This is really weird. You can see for yourself http://myels.com/testing/jimmy/workdash.php

    PHP Code:
     var map = null;
        var geocoder = null;
        var marker = null;
        var point = null;
        <?php
            $key 
    0;
            foreach(
    $results as $key => $contact) {
                
    $results[$key][javavarname] = "address$key";
                
    $varString "var address$key = \"$contact[address1]$contact[city]$contact[state]$contact[zip]\";\n";
                echo 
    $varString;
                
    $key++;
            }
        
    ?>

        
        function load() {
          if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map"));
            geocoder = new GClientGeocoder();
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
    <?
            
    foreach($results as $contact) {
                echo 
    "markAddress(" $contact[javavarname] . ");\n";
                echo 
    "GEvent.addListener(marker, \"click\", function() {\n";
                echo 
    "marker.openInfoWindowHtml(" $contact[javavarname] . ");\n";
                echo 
    "});\n";
            }
    ?>
          }
        }
        function markAddress(address) {
          if (geocoder) {
            geocoder.getLatLng(
              address,
              function(point) {
                if (!point) {
                // alert(address + " not found");
                } else {
                  map.setCenter(point, 7);
                  marker = new GMarker(point);
                  map.addOverlay(marker);
                }
              }
            );
          }
        }

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No one has any clue?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •