CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1

    Help passing Javascript result

    I have the following script that i need to pass the lat and lng to a variable. How can this be accomplished?

    Code:
    <head>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    
    </head>
    <script src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
    <script src=geo.js></script>
    <script>
    function onPositionUpdate(position)
                {
                    var lat = position.coords.latitude;
                    var lng = position.coords.longitude;
                    alert("Current position: " + lat + " " + lng);   <-------[red]This information i want in $coordinates. [/red]
    				
    				
                }
    
                if(navigator.geolocation)
                    navigator.geolocation.getCurrentPosition(onPositionUpdate);
                else
                    alert("navigator.geolocation is not available");
    				
    </script>
    
    <form method="post">
          <input type="text" name="myInput" id="myInput"><br>
            <input type="submit" name="submit" value="Zip Code">
              </form>
    
    <?php
    if(isset($_POST['submit'])){
    $input = $_POST['myInput'];
    }
    else
    {
    $input = '10004';
    }
    
    $zip = $input;
    $json_string =    file_get_contents("http://api.wunderground.com/api/7ec5f6510a4656df/geolookup/conditions/forecast/q/$zip.json");
    $current_parse = json_decode($json_string);
    $parsed_json = json_decode($json_string, true);
    $current = $current_parse->{'current_observation'}->{'temp_f'};
    $parsed = $parsed_json['forecast']['txt_forecast']['forecastday'];
    $loc = $parsed_json['location']['city'];
    $state = $parsed_json['location']['state'];
    
    //pr($parsed_json);
    
    echo 'Weather forecast for: ',$loc , ',' ,$state;
    echo '<center>Currently:  <b><font color="red">' . $current . 'F</center>';
    foreach($parsed as $key => $value)
    {
       echo '<table border="1" width="100%">';
       echo '<tr>';
       echo '<th><b>' . $value['title'] . '</th></font>';
       echo '</tr>';
       echo '<tr>';
       echo '<td width="50%">' .$value['fcttext'] . '</td></font>';
       echo '<td width="10%"><center><img src=' . $value['icon_url'] . '></td>';
       echo '</tr></table>';
    }   
       echo '<div id="radar">';
       echo '<td>';
       echo '</td>';
       echo '</div>'; 
    ?>
    New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.

    www.ethans-space.com

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Help passing Javascript result

    David, you really need to look into tutorials. I've told you this several times...and it seems like you just ignore it.

    Also, many of your questions have been asked and answered many times here on CodeGuru.
    http://forums.codeguru.com/showthrea...vascript%20php
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured