google map app help

#1
[eluser]boony[/eluser]
Hi all,

I've got a small problem with a google map app that I'm working with and hope someone can help solve this issue.

Essentially, I've got a small app that places a marker on a map and then needs to save the lat and long of the position. The code supplied by GOOGLE (below) uses a JavaScript solution. The phpsqlinfo_addrow.php file gets the URI segments which pass the lat and long in the URL call.

Code:
function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var type = document.getElementById("type").value;
      var latlng = marker.getPosition();

      var url = "phpsqlinfo_addrow.php?name=" + name + "&address;=" + address +
                "&type;=" + type + "⪫=" + latlng.lat() + "&lng;=" + latlng.lng();
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          infowindow.close();
          document.getElementById("message")[removed] = "Location added.";
        }
      });
    }

What I want to do is get the lat and long from the marker and pass it to my controller to store the lat and long into the appropriate table. In other words I want to rewrite the following
Code:
var url = "phpsqlinfo_addrow.php?name=" + name + "&address;=" + address +
                "&type;=" + type + "&lat;=" + latlng.lat() + "&lng;=" + latlng.lng();

into something that CI can handle.

Any advice (well not exactly any advice %-P ) greatly appreciated.

Regards

#2
[eluser]eoinmcg[/eluser]
Hi Boony,

Try changing
Code:
var url = "phpsqlinfo_addrow.php?name=" + name + "&address;=" + address +
                "&type;=" + type + "&lat;=" + latlng.lat() + "&lng;=" + latlng.lng();
to:
Code:
var url = "phpsqlinfo_addrow.php/name/" + name + "/address/" + address +
                "/type/" + type + "/lat/" + latlng.lat() + "/lng/" + latlng.lng();

Of course you'll need to change 'phpsqlinfo_addrow.php' to the name of the controller/method in your CI app

You can then use $this->uri->uri_to_assoc(n) to return the segement as an associative array of key/value pairs.
http://ellislab.com/codeigniter/user-gui...s/uri.html

Hope that helps!

#3
[eluser]boony[/eluser]
Quote:Of course you'll need to change 'phpsqlinfo_addrow.php' to the name of the controller/method in your CI app

You can then use $this->uri->uri_to_assoc(n) to return the segement as an associative array of key/value pairs.
Hope that helps!

Thanks eoinmcg,

I've been playing with this for hours and am now totally confused ( wots new I hear Sick).

I'm trying to get back to the controller and am using this (which doesn't seem to work)
Code:
var url = "&lt;?=site_url('mapapp/test_form'); ?&gt;/fname/" + fname + "/lat/" + latlng.lat() + "/lng/" + latlng.lng();


Does that look ok?

Also, I suspect there may be a problem in getting the JavaScript onclick to work. This is the script that is supposed to get the marker position...does CI need to do this differently???

Code:
var map = new google.maps.Map(document.getElementById("map_canvas"), options);
      var html = "<table>" +
                 "<tr><td>Name:</td> <td>&lt;input type='text' id='fname'/&gt; </td> </tr>" +
                   "<tr><td></td><td>&lt;input type='button' value='Save & Close'&gt;&lt;/td></tr>";
      infowindow = new google.maps.InfoWindow({
     content: html
    });

#4
[eluser]eoinmcg[/eluser]
Quote:I’m trying to get back to the controller and am using this (which doesn’t seem to work)

Code:
var url = "&lt;?=site_url('mapapp/test_form'); ?&gt;/fname/" + fname + "/lat/" + latlng.lat() + "/lng/" + latlng.lng();

If you're loading the above javascript in a *.js file the php (&lt;?=site_url('mapapp/test_form'); ?&gtWink isn't going to get parsed. One way around this is to load the javascript as a view in the head of your page this way codeigniter can run the site_url() function.

Quote:Also, I suspect there may be a problem in getting the JavaScript onclick to work. This is the script that is supposed to get the marker position…does CI need to do this differently???

I'm not familiar with the google supplied javascript you're using, but I'd imagine that it shouldn't cause you any problems as it all happens client side. For debugging javascript I can't recommend Firebug enough. console.log() and breakpoints are your friends!

Hope that helps, if not what errors / javascript errors are you gettings?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.