Jump to content

Google Maps


seran128

Recommended Posts

I found a great Google maps API PHP tools but I am having problems getting it to work with my DB. I know the Query works because it has been tested in Navicat

the link to the tools is
http://www.system7designs.com/codebase

I need to pull data from a db ond populate the function like they do below. My code is
[code=php:0]
  <?
  $sql="select * from gs_location WHERE date > NOW() order by date";
echo $sql;
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) { 
  $map->addAddress('$row['address1'],$row['city'],$row['state'] $row['zip']');
}
$map->showMap();
  ?>[/code]



their sample code is

[code=php:0]<?php /**
* Showing valid points table/list with Phoogle Maps
* class developed by Justin Johnson <justinjohnson@system7designs.com>
*/

require_once 'phoogle.php';

$map = new PhoogleMap();
$map->setAPIKey("ABQIAAAA0ksKqHM3yT_xmOPe0DANGRRMlCWGe88WcLmN582t1mFB9gpW6hTvRlzTS-LCJ8nFoD2AGi5vq0X-Yg");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <? $map->printGoogleJS(); ?>
  </head>
  <body>
  <?

  $map->addAddress('208 Dingler Ave, Mooresville, NC 28115');
  $map->addAddress('210 Doster Ave, Mooresville, NC 28115');
  $map->addAddress('300 Dingler Ave, Mooresville, NC 28115');
  $map->showMap();

  ?>
  <h3>The following points are displayed on the map:</h3>
  <h4>(displayed using a table with an id of "my_table")</h4>
  <? $map->showValidPoints("table","my_table"); ?>
  <h4>(dispayed using an unordered list with an id of "my_list")</h4>
  <? $map->showValidPoints("list","my_list"); ?>
    </body>

</html>[/code]
Link to comment
Share on other sites

I dont really understand what you are after, but I will point something out
[code]
$sql="select * from gs_location WHERE date > NOW() order by date";
[/code]
As long as all the entries in your table are in the futute it should pull them out.  date > NOW() are dates in the future..
Link to comment
Share on other sites

[quote author=seran128 link=topic=116812.msg476243#msg476243 date=1164897770]
The problem is
in the

$map->addAddress('$row['address1'],$row['city'],$row['state'] $row['zip']');

Parse error: syntax error, unexpected T_STRING
My quotes are messed up
[/quote]

Indeed they are ;)

Try this instead:
[code]
<?php
$map->addAddress("$row[address1],$row[city],$row[state] $row[zip]");
?>
[/code]
Link to comment
Share on other sites

[quote author=Jocka link=topic=116812.msg476268#msg476268 date=1164898982]
Fix here I think, after seeing obsidians code:

$map->addAddress($row['address1'],$row['city'],$row['state'] . " " . $row['zip']);
[/quote]

Jocka, if you look at the sample code, it's wanting one parameter with the whole address as a string. You've got to parse all the variables into a readable address for it, thus my solution posted ;)
[code]
<?php
$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");
?>
[/code]
Link to comment
Share on other sites

[quote author=mainewoods link=topic=116812.msg476434#msg476434 date=1164916005]
To get to googles format, the commas will have to become part of the string:
[code]$map->addAddress($row['address1'] . ', ' . $row['city'] . ', ' .$row['state'] . " " . $row['zip']);[/code]

Haha... what is it with people rewriting the same solution over and over again today? lol


[/quote]
Link to comment
Share on other sites

My solution is different to your solution obsidian, your's looks like this:
[code]$map->addAddress($row['address1'],$row['city'],$row['state'] . " " . $row['zip']);[/code]
mine looks like this:
[code]$map->addAddress($row['address1'] . ', ' . $row['city'] . ', ' .$row['state'] . " " . $row['zip']);[/code]
--yours passes multiple parameters separated by commas while mine passes one string parameter with commas as part of the string.  That's what the example from google was formatted as, not multiple parameters.  I couldn't tell from the posts whether the problem was solved or not so that's why I submitted my answer which [i]is different [/i] than yours.
From Google sample code:
[code]$map->addAddress('208 Dingler Ave, Mooresville, NC 28115');[/code]
Link to comment
Share on other sites

[quote author=mainewoods link=topic=116812.msg477087#msg477087 date=1164993023]
My solution is different to your solution obsidian, your's looks like this:
[code]$map->addAddress($row['address1'],$row['city'],$row['state'] . " " . $row['zip']);[/code]
mine looks like this:
[code]$map->addAddress($row['address1'] . ', ' . $row['city'] . ', ' .$row['state'] . " " . $row['zip']);[/code]
--yours passes multiple parameters separated by commas while mine passes one string parameter with commas as part of the string.  That's what the example from google was formatted as, not multiple parameters.  I couldn't tell from the posts whether the problem was solved or not so that's why I submitted my answer which [i]is different [/i] than yours.
From Google sample code:
[code]$map->addAddress('208 Dingler Ave, Mooresville, NC 28115');[/code]
[/quote]

Not true at all. Look closely at my posts. You need to read the [b]whole[/b] of it before you branch off on a tangent ;) . [b]Both[/b] my posts that have code written are passing one string with all the variables within it, [i]just like the sample code requires[/i]! In fact, I'll quote my response to Jocka where it sounds like you got your solution from lol:
[quote author=obsidian link=topic=116812.msg476281#msg476281 date=1164899575]
Jocka, if you look at the sample code, it's wanting one parameter with the whole address as a string. You've got to parse all the variables into a readable address for it, thus my solution posted ;)
[code]
<?php
$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");
?>
[/code]
[/quote]

Now, back to my original statement... What's with everyone rewriting the same solution over and over? Haha :D
Link to comment
Share on other sites

I copied that from your post obsidian, I guess from the wrong part of the post(oops). Getting confused with all that jumping in and out of single quotes, double quotes, and whatnot is one of the easiest mistakes to make.  Causes me more php and javascript parse errors than anything.

Isn't the way you wrote it supposed to be poor coding practice because there should be single quotes around the variable names between the []s:
[code]<?php
$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");
?>[/code]
--recommended instead?
[code]<?php
$map->addAddress("$row['address1'], $row['city'], $row['state'] $row['zip']");
?>[/code]
Link to comment
Share on other sites

[quote author=mainewoods link=topic=116812.msg477138#msg477138 date=1164997391]
...Getting confused with all that jumping in and out of single quotes, double quotes, and whatnot is one of the easiest mistakes to make.  Causes me more php and javascript parse errors than anything.[/quote]
I [b]completely[/b] understand how that causes problems. I will admit that getting the hang of quotes in different languages is about the hardest thing for me, too ;)

[quote author=mainewoods link=topic=116812.msg477138#msg477138 date=1164997391]
Isn't the way you wrote it supposed to be poor coding practice because there should be single quotes around the variable names between the []s:
[code]<?php
$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");
?>[/code]
--recommended instead?
[code]<?php
$map->addAddress("$row['address1'], $row['city'], $row['state'] $row['zip']");
?>[/code]
[/quote]

Actually, that's an excellent question. If you try both the strings you posted above, you'll actually get warnings for your second one. When you're within double quotes, you don't need any singles to delimit the keys in your array. If you like to keep consistent, though, use brackets around each variable, and you can then print them as you would outside of quotes:
[code]
<?php
$map->addAddress("{$row['address1']}, {$row['city']}, {$row['state']} {$row['zip']}");
?>
[/code]

Nice and confusing, isn't it? :D
Link to comment
Share on other sites

I was thinking and I thought that leaving the single quotes off of the index would be more of a problem with javascript than php because in js it could then easily resolve to an actual variable defined earlier in the program, ie:
[code]jsvar[string][/code]
could be interpreted as a varaible named string defined earlier in the js or as the string 'string' which would then be the array index name.  But in php:
[code]$phpvar[indexstring];[/code]
--seems more safe - no $ in between the [] so it can't be interpreted as a variable, but is there some constants preprocessor feature of php that could still cause a problem?  I've been dutifully putting those single quotes in my php array references and it would be nice if I could give that up and still be safe.

Link to comment
Share on other sites

[quote author=mainewoods link=topic=116812.msg477281#msg477281 date=1165013167]

[code]$phpvar[indexstring];[/code]
--seems more safe - no $ in between the [] so it can't be interpreted as a variable, but is there some constants preprocessor feature of php that could still cause a problem?  I've been dutifully putting those single quotes in my php array references and it would be nice if I could give that up and still be safe.
[/quote]

Really, it depends on how much of a stickler you are for your code. If you leave off the quotes from your array key names within double quotes, that is correct syntax. However, if you leave them off outside of double quotes, your script will throw warnings. Your code will still function properly, and if you have all error suppression turned on, you may never know there is an issue, but PHP will [i]assume[/i] that you are trying to name a key, and it will parse it as such, but it will also throw a warning to the screen.
Link to comment
Share on other sites

  • 1 month later...
i put all my variables in an array to make a single variable to call the map with...

[quote]$tmpq = array();
$fulladdress= $address;
$tmpq[] = ",";
$tmpq[] .= $city;
$tmpq[] .= ",";
$tmpq[] .= $state;
$tmpq[] .= $zip;
$fulladdress .= implode(' ',$tmpq);
$map->addAddress($fulladdress);[/quote]

that's how i did it b/c i already had those variables stored in my DB so just combine it in the map format and voolah.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.