Pass JS values to PHP, in Google Maps API

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Loxy3
Forum Newbie
Posts: 2
Joined: Mon Feb 22, 2010 5:25 pm

Pass JS values to PHP, in Google Maps API

Post by Loxy3 »

Cheers !

I am a newbie here, and also my English isn't the best in the world...

So, i have a question in a script of mine:

I am trying to give the user of my website the ability to type the "From" and "To" values from a journey,
and then the website must display the route of it.

I use google map api, but i 've stuck in this point:

Code: Select all

function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
 
        setDirections("Salonica", "Athens", "en_US");
      }
    }
I am initializing the function initialize() in header, and using this :

Code: Select all

<form method="post" action="offer.php" name="jrndetform" id="jrndetform action="#" onsubmit="setDirections(this.From.value, this.To.value); return false">
       <table class="b" border=0>
    <tr>
        <td><label class="a"  for="From" >From:</label></td>
        <td><input  readonly="readonly" id="fromAddress" name="From" value="<? $from ?>" ></td>
        
        <td cellspacing=10 align="right"><div id="map_canvas" style="width: 300px; height: 200px"></div></td></tr>
    
    <tr>
        <td><label class="a"  for="To" >To:</label></td>
        <td><input  readonly="readonly" id="toAddress" name="To" value="<? $to ?>" ></td></tr>
     
to display it.

How can i achieve to type the start and end point of the journey and display the route in the site?

Hope,i gave you the point of my prob...
Loxy3
Forum Newbie
Posts: 2
Joined: Mon Feb 22, 2010 5:25 pm

Re: Pass JS values to PHP, in Google Maps API

Post by Loxy3 »

OK, solved...

If anyone is interested in , just move the JS script from the header to the body ,
and add this line :

Code: Select all

var from = "<? echo $from ; ?>" ;
and change the last line of initialize() to:

Code: Select all

setDirections(from , to, "en_US");
Post Reply