jacem
Posts: 87
|
Posted: 09/05/2011, 12:15 AM |
|
I have been using the excellent CodeCharge tools Google Map wizard however I have found that too many geocode requests in a short amount of time can cause the dropping of 'pins' from the map. Google has per day limits and if it thinks you are going to bust those limits, even during a short 10 second period, will result in google starting to not reply to all the geocode requests:- dropping pins from the map being generated.
My cunning plan is to store the lat / long detail in the table with the addresses I am geocoding once only so that I don't need to do geocode requests even time the map is created - a pin generated in the google maps api from lat / long coordinates does not result in a geocode request so there would be no limit to bust when a user does a map creating search.
However I have no understanding on how to, within codecharge, do a bulk update of a address records with the responding la / long coordinates that will come from a once only run of geocode requests for each record in a table...I have been looking through the Google API but its not apparent to me how this works with Codecharge. Anyone worked in this area can point me in the right direction PHP/CodeCharge wise.
|
|
|
mamboBROWN
Posts: 1713
|
Posted: 09/05/2011, 10:25 AM |
|
jacem,
Your going to have to either generate SQL code to do a bulk update or create a (MySQL) stored procedure to do it for you. I personally have not worked that much with geo tagging but I will help where I can.
|
|
|
ckroon
Posts: 869
|
Posted: 09/05/2011, 10:56 AM |
|
I have just completed working on that very thing.
I used Yahoo place finder API as it allows for 50,000 requests per day :) very nice!
I have a table: student_table and on it are the address,city and zip as well as the lat and long fields(cl_lat, cl_long) and a field to indicate if the record has been processed yet: cl_yahooget (Y/N)
Be sure to register with yahoo to get your unique API key
This code gets the records, finds the lat/long, updates ht table, then marks the cl_yahooget as Y.. ten moves on to the next record.
Have Fun!
error_reporting(0);
set_time_limit(0);
global $DBConnection1;
$db = new clsDBConnection1;
$db1 = new clsDBConnection1;
$sql = "SELECT studentid as sid, city as city, ";
$sql.= "address as add, state as state,mailingzip as zip ";
$sql.= " FROM student_table WHERE cl_yahooget = 'N' AND status <> '3' ";
$db->query($sql);
//echo "$sql<br>";
while($db->next_record())
{
$sid = $db->f("sid");
$zip = $db->f("zip");
$city =$db->f("city");
$add = $db->f("add");
$state = $db->f("state");
//echo "add1=$add<br>state=$state<br>city=$city<br>";
/////////////////
$appid = "//YOUR APPID HERE//";
// $geourl = "http://local.yahooapis.com/MapsService/V1/geocode?appid=".$appid."&location=". $add. "+" . $city . "+" . $state;
$geourl = "http://where.yahooapis.com/geocode?q=". $add. "+" . $city . ",+" . $state."&appid=".$appid;
$geourl = str_replace(" ","+",$geourl);
echo "$geourl<br>";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $geourl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$xmlContent = trim(curl_exec($c));
curl_close($c);
$xmlObject = simplexml_load_string($xmlContent);
$latitude = (string)$xmlObject->Result->latitude;
$longitude = (string)$xmlObject->Result->longitude;
/////////////////////////////////////////
$lat = $latitude;
$long = $longitude;
// -------------------------
//////////////////////////////////////////
if ($lat <> "" AND $long <> "")
{
$sql = " UPDATE student_table set cl_latitude = '$lat', ";
$sql.= " cl_longitude = '$long',cl_yahooget = 'Y' ";
$sql.=" WHERE studentid = '$sid' ";
$db1->query($sql);
//echo "$sql<br>";
}
$city= "";
$add = "";
$state = "";
}//end get sid
_________________
Walter Kempees...you are dearly missed. |
|
|
jacem
Posts: 87
|
Posted: 09/09/2011, 9:19 PM |
|
Thanks for the code snippit CK - I will give it try in a few days and report back...
|
|
|
mamboBROWN
Posts: 1713
|
Posted: 09/20/2011, 8:58 PM |
|
jacem,
Has the solution that ckroon given you worked? If so can you put [RESOLVED] or [SOLVED] in the thread header. Thanks.
|
|
|
|