Google Groups Home
Help | Sign in
Passing Lat + Lng to a php script
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Donal  
View profile
(1 user)  More options Jul 4, 5:45 am
From: Donal <donal.ca...@gmail.com>
Date: Fri, 4 Jul 2008 02:45:21 -0700 (PDT)
Local: Fri, Jul 4 2008 5:45 am
Subject: Passing Lat + Lng to a php script
Hi all

Am having a problem passing latitude and longitude to a php script
which then writes to a database.

Basically what I'm trying to do is allow a user to upload a
file(video) inside a marker infowindow via a php script. I am using
the google writing to a database tutorial code modified to enable
uploads.

Code for the map and php script is below.....I think the problem lies
with the fact that the html form is calling up_addrow.php and then
calling the saveData() function which also tries to call
up_addrow.php. The uploads are making it to the database fine but the
lat&lng are not and are populated with zeros.

Any help would be much appreciated

//MAP
function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);

        GEvent.addListener(map, "click", function(overlay, latlng) {
          if (latlng) {
            marker = new GMarker(latlng, {draggable:true});
            GEvent.addListener(marker, "click", function() {
              var html ="<form method='post' enctype='multipart/form-
data' action='up_addrow.php'>"+
                        "<table width='350' border='0' cellpadding='1' cellspacing='1'>"+
                        "<tr>"+
                        "<td width='246'>"+
                        "<input type='hidden' name='MAX_FILE_SIZE' value='2000000'>"+
                        "<input name='userfile' type='file' id='userfile'>"+
                        "</td>"+
                        "<td width='80'><input name='upload' type='submit' class='box'
id='upload' value='Upload' onSubmit='saveData()'></td>"+
                        "</tr>"+
                        "</table>"+
                        "</form>";

              marker.openInfoWindow(html);

            });
            map.addOverlay(marker);
          }
        });

      }
    }

    function saveData() {
      var latlng = marker.getLatLng();
      var lat = latlng.lat();
      var lng = latlng.lng();

      var url = "up_addrow.php?lat=" + lat + "&lng=" + lng;
      GDownloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          marker.closeInfoWindow();
          document.getElementById("message").innerHTML = "Location
added.";
        }
      });
    }
    </script>

//PHP SCRIPT

<?php
require("up_dbinfo.php");

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

// Gets data from URL parameters
$lat = $_GET['lat'];
$lng = $_GET['lng'];

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);

}

include 'library/config.php';
include 'library/opendb.php';

// Opens a connection to a MySQL server
$connection=mysql_connect ("localhost", $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());

}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());

}

$query = "INSERT INTO upload (name, size, type, content,lat, lng ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$lat',
'$lng')";

mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';

echo "<br>File $fileName uploaded<br>";

}

?>

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blind-Summit  
View profile
 More options Jul 4, 6:02 am
From: Blind-Summit <webmas...@blind-summit.co.uk>
Date: Fri, 4 Jul 2008 03:02:14 -0700 (PDT)
Local: Fri, Jul 4 2008 6:02 am
Subject: Re: Passing Lat + Lng to a php script
You could set 2 hidden fields in your form:

GEvent.addListener(map, "click", function(overlay, latlng) {
   if (latlng) {
      marker = new GMarker(latlng, {draggable:true});
      var latlng = marker.getLatLng();
      var lat = latlng.lat();
      var lng = latlng.lng();
      GEvent.addListener(marker, "click", function() {
         var html ="<form method='post' enctype='multipart/form-data'
action='up_addrow.php'>
         <input type='hidden' name='lat' value='"+lat+"' />
         <input type='hidden' name='lng' value='"+lng+"' /> .......

Because you already have the marker in the click function, you can get
the lat / lng from it and pass that into your form.

Your save data function returns 0 for the lat / lng because "marker"
isn't a global variable, hence you can't call marker.getLatLng().

Hope this helps you on your way

Alex Holsgrove


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Donal  
View profile
 More options Jul 4, 9:02 am
From: Donal <donal.ca...@gmail.com>
Date: Fri, 4 Jul 2008 06:02:08 -0700 (PDT)
Local: Fri, Jul 4 2008 9:02 am
Subject: Re: Passing Lat + Lng to a php script
Hi Alex

Thanks for the help its most appreciated - do I need to do anything in
the php script in order to accept these hidden variables? i.e. other
than

$lat = $_GET['lat'];
$lng = $_GET['lng'];

Thanks
Donal

On Jul 4, 11:02 am, Blind-Summit <webmas...@blind-summit.co.uk> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google