Thanks, owel.
You bring up great points about the irregular shape of zip code areas. My initial study of this project brought me to a web service that has an api which will return a list of the zip codes in the given radius as json or xml. if I simply provide the center zip code and the radius size in miles and the format I want the data returned to me in. ie. 98012 and 5 miles and JSON.
It is a subscription service which is ok at the moment as I feel the expense and time to reinvent the wheel and do all the maintenance of the dataset of zip code data from the usps and other sources of this info are too time-consuming.
My project is really about having a group of people meet at a venue on a regular basis. Each of these venues will be unique to each zip code. The group of people will represent providers of unique skill sets with only one provider of each unique skill set represented and allowed at each venue.
The categories of skill sets represented are fixed and are the same for each group venue.
What my algorithm and eventual application solution must do is to prepare a list of providers for potential consumers of the skill sets to discover a completed list of providers who offer that skill set. The problem is that there may not be a provider of a certain skill category that is a member of the venue represented by the zip code the consumer lives in, so the algorithm must then search outward to the next closest zip code area
and confirm there is an active group in the zip code and see if there is a provider of the yet unrepresented skill set available from that group to be listed in the resultant list for the consumer to view.
I am using another web-based data management service which has an API to store all the db tables of skill providers and venues and associated things. This service allows me to embed the tables in external websites or send api calls and get raw json back as well as do posts to change the tables using php, javascript or some other language.
My stakeholder is a spreadsheet wiz but knows nothing about coding web apps. So he is doing all the data entry using the data management system and I am writing the web ui and backend and middleware to tie all the web services together. I may even try using ifttt and zapier if possible.
SO…
I have gotten some code working to grab the json from the web service and convert the json to a php array so I can work with the individual members of the data set. ( there may be a better way but I can’t seem to figure out how to programmatically access individual members of the JSON object returned.)
Here is a sample of what I get from the code I have.
<!DOCTYPE html>
<html>
<body>
<?php
/*
** ZipFinder
** Michael McGinn
** 3/30/2018
**
**
** Here is what I have so far. I have stiped out the api key and the web site of the zip service so I don't spam.
** This is rough ugly code but you get the idea I hope.
** I simply send data to this app via a web form post.
*/
$key="";
$zipf = $_POST['zip'];
$zipa="&zip=".$zipf;
$radiusa="&radius=".$_POST["radius"];
$formata="&format=".$_POST["format"];
$url="https://www.example.com/webservices/radius.php?";
$jsoncall=$url.$key.$zipa.$radiusa.$formata;
//echo "<BR>".$jsoncall;
?json = file_get_contents($jsoncall);//grabs the output of the api call
//echo "<br><BR>json=".$json."<br><BR>";
$dealers=array();
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
$field=0;
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
$field=0;
$dealers[$key][$field][0]=$key;
$dealer=$key;
} else {
$dealers[$dealer][$field][1]=$key;
$dealers[$dealer][$field][2]=$val;
$field++;
}
}
echo "Number of Dealers=".count($dealers)."<BR>";
$dealercount=count($dealers)-1;
for($i=0;$i<=$dealercount;$i++){
echo "<BR>Exracted Value=".$dealers[$i][0][0];
echo "<BR>Exracted Value=".$dealers[$i][0][1];
echo "<BR>Exracted Value=".$dealers[$i][0][2];
echo "<BR>Exracted Value=".$dealers[$i][1][1];
echo "<BR>Exracted Value=".$dealers[$i][1][2];
echo "<BR>Exracted Value=".$dealers[$i][2][1];
echo "<BR>Exracted Value=".$dealers[$i][2][2];
echo "<BR>Exracted Value=".$dealers[$i][3][1];
echo "<BR>Exracted Value=".$dealers[$i][3][2];
echo "<BR>Exracted Value=".$dealers[$i][4][1];
echo "<BR>Exracted Value=".$dealers[$i][4][2];
echo "<BR>----<BR>";
}
?>
</body>
</html>
Here is the output.
https://www.example.com/webservices/radius.php?key=?????&zip=98012&radius=5&format=json
json={"results":[{"zip":"98012","city":"Bothell","county":"Snohomish","state":"WA","distance":"0.0"},{"zip":"98082","city":"Mill Creek","county":"Snohomish","state":"WA","distance":"1.7"},{"zip":"98021","city":"Bothell","county":"Snohomish","state":"WA","distance":"2.8"},{"zip":"98087","city":"Lynnwood","county":"Snohomish","state":"WA","distance":"3.0"},{"zip":"98036","city":"Lynnwood","county":"Snohomish","state":"WA","distance":"3.1"},{"zip":"98037","city":"Lynnwood","county":"Snohomish","state":"WA","distance":"3.4"},{"zip":"98208","city":"Everett","county":"Snohomish","state":"WA","distance":"4.3"},{"zip":"98046","city":"Lynnwood","county":"Snohomish","state":"WA","distance":"4.5"}]}
Number of Dealers=9
Exracted Value=0
Exracted Value=zip
Exracted Value=98012
Exracted Value=city
Exracted Value=Bothell
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=0.0
----
Exracted Value=1
Exracted Value=zip
Exracted Value=98082
Exracted Value=city
Exracted Value=Mill Creek
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=1.7
----
Exracted Value=2
Exracted Value=zip
Exracted Value=98021
Exracted Value=city
Exracted Value=Bothell
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=2.8
----
Exracted Value=3
Exracted Value=zip
Exracted Value=98087
Exracted Value=city
Exracted Value=Lynnwood
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=3.0
----
Exracted Value=4
Exracted Value=zip
Exracted Value=98036
Exracted Value=city
Exracted Value=Lynnwood
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=3.1
----
Exracted Value=5
Exracted Value=zip
Exracted Value=98037
Exracted Value=city
Exracted Value=Lynnwood
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=3.4
----
Exracted Value=6
Exracted Value=zip
Exracted Value=98208
Exracted Value=city
Exracted Value=Everett
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=4.3
----
Exracted Value=7
Exracted Value=zip
Exracted Value=98046
Exracted Value=city
Exracted Value=Lynnwood
Exracted Value=county
Exracted Value=Snohomish
Exracted Value=state
Exracted Value=WA
Exracted Value=distance
Exracted Value=4.5
----
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
Exracted Value=
----
So I’m now working on the code to process this list and do the search for the groups by zip and prepare the list of skill providers.
I am also open to any hints on how to refactor this code so I can skip parsing the json into the array and just directly access each member of the json object.
example:
$nextzip=$jsonIterator??? //what is the syntax so that $nextzip would be set to the 2nd zip code in the returned json dataset.
Wanna work on this with me?
Update:
I figured out how to access the individual members of the json result set.
$json = file_get_contents('https://www.???.com/webservices/radius.php?key=????????&zip=98012&radius=5&format=json');
$myresult = json_decode($json);
//$json = file_get_contents($jsoncall);//grabs the output of the api call
echo "<br><BR>json=".$json."<br><BR>";
echo "<br>NUMBER OF RESULTS:".count($myresult->results);
$resultsa=count($myresult->results);
for($l=0;$l<=$resultsa;$l++){
echo "<BR>ZIP:".$myresult->results[$l]->zip;
echo "<BR>CITY:".$myresult->results[$l]->city;
echo "<BR>COUNTY:".$myresult->results[$l]->county;
echo "<BR>ST:".$myresult->results[$l]->st;
echo "<BR>DISTANCE:".$myresult->results[$l]->distance;
}
Hunting on stack overflow. found it.