PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Jul 14, 2020 7:35 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Jul 20, 2006 10:00 am 
Offline
Forum Commoner
User avatar

Joined: Mon Jun 05, 2006 9:53 am
Posts: 77
Weirdan | Please use
Syntax: [ Download ] [ Hide ]
,
[syntax=php]and
Syntax: [ Download ] [ Hide ]
  1. tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: to learn how to do it too. 
  2.  
  3.  
  4.  
  5.  
  6.  
  7. 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. 
  8.  
  9.  
  10.  
  11. [syntax="javascript"] 
  12.  
  13. var map = null; 
  14.  
  15. var geocoder = null; 
  16.  
  17. <?php 
  18.  
  19. $key = 0; 
  20.  
  21. foreach($results as $key => $contact) { 
  22.  
  23. $results[$key][javavarname] = "address$key"; 
  24.  
  25. $varString = "var address$key = \"$contact[address1], $contact[city], $contact[state], $contact[zip]\";\n"; 
  26.  
  27. echo $varString; 
  28.  
  29. $key++; 
  30.  
  31.  
  32. ?> 
  33.  
  34.  
  35.  
  36. function markAddress(address) { 
  37.  
  38. if (geocoder) { 
  39.  
  40. geocoder.getLatLng( 
  41.  
  42. address, 
  43.  
  44. function(point) { 
  45.  
  46. if (!point) { 
  47.  
  48. // alert(address + " not found"); 
  49.  
  50. } else { 
  51.  
  52. map.setCenter(point, 7); 
  53.  
  54. var marker = new GMarker(point); 
  55.  
  56. map.addOverlay(marker); 
  57.  
  58.  
  59.  
  60. ); 
  61.  
  62.  
  63.  
  64.  
  65.  
  66. function load() { 
  67.  
  68. if (GBrowserIsCompatible()) { 
  69.  
  70. map = new GMap2(document.getElementById("map")); 
  71.  
  72. geocoder = new GClientGeocoder(); 
  73.  
  74. map.addControl(new GSmallMapControl()); 
  75.  
  76. map.addControl(new GMapTypeControl()); 
  77.  
  78.  
  79.  
  80. <? 
  81.  
  82. foreach($results as $contact) { 
  83.  
  84. echo "markAddress(" . $contact[javavarname] . ");\n"; 
  85.  
  86. echo "GEvent.addListener(marker, \"click\", function() {\n"; 
  87.  
  88. echo "marker.openInfoWindowHtml(" . $contact[javavarname] . ");\n"; 
  89.  
  90. echo "});\n"; 
  91.  
  92.  
  93. ?> 
  94.  
  95.  
  96. }[/syntax] 
  97.  
  98.  
  99.  
  100.  
  101.  
  102. Weirdan | Please use 
Syntax: [ Download ] [ Hide ]
,
[syntax=php]and
Syntax: [ Download ] [ Hide ]
  1. tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: to learn how to do it too. 


Last edited by hydroxide on Fri Jul 21, 2006 9:01 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 11:21 am 
Offline
Site Administrator
User avatar

Joined: Tue Sep 09, 2003 6:04 pm
Posts: 14293
Location: Fremont, CA, USA
It could be in the way that PHP is being used. There are some things you could clean up a bit.

Syntax: [ Download ] [ Hide ]
$varString = "var address$key = \"$contact[address1], $contact[city], $contact[state], $contact[zip]\";\n";


Maybe do this...
Syntax: [ Download ] [ Hide ]
$varString = 'var address' . $key . ' = "' . $contact[address1].$contact[city].$contact[state].$contact[zip] . '";';

$varString .= "\n";


And when using arrays, make sure to enclose the index in quotes...
Syntax: [ Download ] [ Hide ]
echo "markAddress(" . $contact[javavarname] . ");\n";

echo "GEvent.addListener(marker, \"click\", function() {\n";

echo "marker.openInfoWindowHtml(" . $contact[javavarname] . ");\n";


might be better off as..
Syntax: [ Download ] [ Hide ]
echo "markAddress(" . $contact['javavarname'] . ");\n";

echo "GEvent.addListener(marker, \"click\", function() {\n";

echo "marker.openInfoWindowHtml(" . $contact['javavarname'] . ");\n";


These are just possibilities, no guarantees.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 11:43 am 
Offline
Forum Commoner
User avatar

Joined: Mon Jun 05, 2006 9:53 am
Posts: 77
I'm not sure if the way the PHP is set up is the problem. I'm getting the proper output from my php file. You can see for yourself here . I'm out of ideas :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 12:11 pm 
Offline
Forum Commoner
User avatar

Joined: Mon Jun 05, 2006 9:53 am
Posts: 77
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

Syntax: [ Download ] [ Hide ]
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);

            }

          }

        );

      }

    }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 11:27 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
Javascript :arrow: Client Side.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 6:56 am 
Offline
Forum Commoner
User avatar

Joined: Mon Jun 05, 2006 9:53 am
Posts: 77
Sorry about that


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 1:42 pm 
Offline
Forum Commoner
User avatar

Joined: Mon Jun 05, 2006 9:53 am
Posts: 77
*sigh* fixed this finally: JS 0 | hydroxide 1

Syntax: [ Download ] [ Hide ]
var map = null;

    var geocoder = null;

        <?php

                $key = 0;

                foreach($results as $key => $contact) {

                        $results[$key][javavarname] = "address$key";

                        $results[$key][javavarname2] = "address$key" . "_phone";

                       

                        $varString = "var address$key = \"$contact[address1], $contact[city], $contact[state], $contact[zip]\";\n";

                        echo $varString;



                        $varString2 = "var address$key" . "_phone = \"<b>$contact[cliname]</b><br>$contact[address1]<br>$contact[zip] $contact[city], $contact[state]<br>$contact[phone]\";\n";

                        echo $varString2;

                        $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] . ", " . $contact[javavarname2] . ");\n";

                }

?>

      }

    }



    function markAddress(address, info) {

      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);

<?

                        echo "GEvent.addListener(marker, \"click\", function() {\n";

                        echo "marker.openInfoWindowHtml(info);\n";

                        echo "});\n";                  



?>                       

            }

          }

        );

      }

    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group