[Google] Map advice needed

Hey folks

I have a project, where i will need to locate potentially a lot of people on a map of the USA. they will be over the entire USA, so i assume, that i will need to start by showing not individual pins on a USA map - but similar to Google Analytics - to start with States, and then drill down to a resolution that is low enough to see pins.

i will have my data coming from an MSSQL database  - probably using ZIP codes.

so -
1) can anyone point me in the direction of studying the basics here - or even getting some kind of off the shelf product.

2) can Google take ZIP codes as pointers, or does it need long/lat specifications?

3) are there other ideas to use - other than Google maps?

Thanks!!
kneidelsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thedwillCommented:
0
thedwillCommented:
0
kneidelsAuthor Commented:
thanks thedwill, i have seen all i these - i was just hoping to get ideas from other folks.
maybe for example, gmaps isnt the way to go - maybe there are better solutions etc...

thanks
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Ray PaseurCommented:
Stick with Google Maps - it is the lingua franca of geolocation.

Google cannot take zip codes directly as geocodes, but it can translate them nicely for you.  However be aware of the limitations of zip codes.  They do not describe a place; they describe a postal carrier's route.  In Manhattan that is a very small area.  In Nevada, it may be hundreds of miles.

Both Yahoo and Google can geocode almost any legitimate address.  The better the address, the better the precision.  Here is my PHP class showing how to call the geocoders.  HTH, ~Ray
<?php // RAY_class_SimpleGeoCoder.php
error_reporting(E_ALL);

// API KEYS, ETC., IF REQUIRED
// require_once('_config.php');


// PUT UP A FORM TO RECEIVE THE ADDRESS INFORMATION
if (empty($_GET))
{
?>

<html><head><title>Yahoo/Google SimpleGeoCoder Demo</title></head>
<body>
<form method="get">
Addr: <input type="text" name="a" autocomplete="off" />
City: <input type="text" name="c" autocomplete="off" />
ST:   <input type="text" name="s" autocomplete="off" size="2" />
Zip:  <input type="text" name="z" autocomplete="off" size="8" />
<input type="submit" name="_go" value="go" />
</form>
</body>
</html>

<?php
    die();
}


// A FREEFORM LOCATION STATEMENT IS OPTIONAL - GET ADDRESS, CITY, STATE, ZIP FROM THE URL
$location = '';
if ($_GET["a"] != '') { $location .= $_GET["a"] . ' '; }
if ($_GET["c"] != '') { $location .= $_GET["c"] . ' '; }
if ($_GET["s"] != '') { $location .= $_GET["s"] . ' '; }
if ($_GET["z"] != '') { $location .= $_GET["a"] . ' '; }
$location = trim($location);


// PREPARE THE GEOCODER
$demo          = new SimpleGeoCoder;
$demo->address = $_GET["a"];
$demo->city    = $_GET["c"];
$demo->state   = $_GET["s"];
$demo->zip     = $_GET["z"];

// TEST THE YAHOO! GEOCODER
$demo->geocodeYahoo();
echo "<pre>\n\nYAHOO! ";
print_rr($demo);
echo "</pre>\n";

// TEST THE GOOGLE GEOCODER
$demo->geocodeGoogle();
echo "<pre>\n\nGOOGLE ";
print_rr($demo);
echo "</pre>\n";


// ALL DONE
die();



// SIMPLE GEOCODER CLASS
class SimpleGeoCoder
{

// DECLARE THE INPUT DATA
    public $location; // USE THIS FOR A FREEFORM QUERY, OR USE THE PARTS
    public $address;
    public $city;
    public $state;
    public $zip;

// DECLARE THE WORKING DATA
    private $precis; // TEXTUAL PRECISION FROM YAHOO
    private $yfp, $yahooUrl,  $yahooResponse,  $ydata;
    private $gfp, $googleUrl, $googleResponse, $gdata;

// DECLARE THE OUTPUT DATA
    public $latitude;
    public $longitude;
    public $precision;
    public $warning;
    public $geocoder;

// DECLARE THE CONSTRUCTOR
    public function __construct()
    {
        $this->latitude  = 0.0;
        $this->longitude = 0.0;
        $this->precision = FALSE; // WANT A VALUE OF 5 OR HIGHER, HIGHER IS BETTER
        $this->warning   = '';
        $this->geocoder  = '';
        unset($this->precis);
    }

// DECLARE THE DATA-CLEANUP
    private function _cleanup($str)
    {
        $str = preg_replace('/[^\' a-zA-Z0-9&!#$%()"+:?\/@,_\.\-]/', '', $str);
        return trim(preg_replace('/\s\s+/', ' ', $str));
    }

// DECLARE THE YAHOO! VERSION OF THE WORKHORSE
    public function geocodeYahoo()
    {
        if (!defined('YAHOO_API')) define('YAHOO_API', 'YAHOO_API');
        $this->geocoder = 'Yahoo!';
        $yahooUrl       = "http://local.yahooapis.com/MapsService/V1/geocode?&appid=" . YAHOO_API;
        if ($this->location != '') // YOU CAN ASK FOR A FREEFORM QUERY
        {
            $yahooUrl .= "&location=" . urlencode($this->_cleanup($this->location));
        }
        else // YOU CAN ASK FOR INDIVIDUAL PIECES OF AN ADDRESS
        {
            $yahooUrl .= "&street=" . urlencode($this->_cleanup($this->address));
            $yahooUrl .= "&city="   . urlencode($this->_cleanup($this->city));
            $yahooUrl .= "&state="  . urlencode($this->_cleanup($this->state));
            $yahooUrl .= "&zip="    . urlencode($this->_cleanup($this->zip));
        }

// EXECUTE YAHOO GEOCODER QUERY
// NOTE - USE ERROR SUPPRESSION OR IT WILL BARK OUT THE YAHOO API KEY - ON FAILURE RETURNS HTTP 400 BAD REQUEST
        if ($yfp = @fopen($yahooUrl, 'r'))
        {
            $yahooResponse = '';
            while (!feof($yfp)) { $yahooResponse .= fgets($yfp); }
            fclose($yfp);
        }
        else
        {
            return FALSE;
        }

// EXAMINE THE RESULT
        if ($yahooResponse != '') // NOT EMPTY, WE GOT DATA
        {
            $ydata    = new SimpleXMLElement($yahooResponse);

// CHECK FOR ANY ERROR MESSAGE, IF NONE, EXTRACT THE DATA POINTS
            $yerror    = $ydata->Message;
            if ($yerror == '')
            {
                $this->precis    = (string)$ydata->Result["precision"];
                $this->warning   = (string)$ydata->Result["warning"];
                $this->latitude  = (string)$ydata->Result->Latitude;
                $this->longitude = (string)$ydata->Result->Longitude;

// THESE STATEMENTS CAN BE USED TO RETURN NORMALIZED ADDRESS
                $this->address   = (string)$ydata->Result->Address;
                $this->city      = (string)$ydata->Result->City;
                $this->state     = (string)$ydata->Result->State;
                $this->zip       = (string)$ydata->Result->Zip;

// SET PRECISION TO A NUMBER VALUE
                if ($this->precis == 'zip')     { $this->precision = "5"; }
                if ($this->precis == 'street')  { $this->precision = "6"; }
                if ($this->precis == 'address') { $this->precision = "8"; }
            }
            else
            {
                return FALSE;
            }
        }
        else  // NO RESULT - SOMETHING IS SICK AT YAHOO
        {
            return FALSE;
        }
        return TRUE;
    } // END function geocodeYahoo



// DECLARE THE GOOGLE VERSION OF THE WORKHORSE
    public function geocodeGoogle()
    {
        if (!defined('GOOGLE_API')) define('GOOGLE_API', 'GOOGLE_API');
        $this->geocoder = 'Google';
        $googleUrl      = "http://maps.google.com/maps/geo?key=" . GOOGLE_API . "&output=csv";

        if ($this->location != '') // YOU CAN ASK FOR A FREEFORM QUERY
        {
            $googleUrl .= "&q=" . urlencode($this->_cleanup($this->location));
        }
        else // YOU CAN ASK FOR INDIVIDUAL PIECES OF AN ADDRESS
        {
            $googleUrl .= "&q="
                       . urlencode(trim(
                         $this->_cleanup($this->address) . ' '
                       . $this->_cleanup($this->city)    . ' '
                       . $this->_cleanup($this->state)   . ' '
                       . $this->_cleanup($this->zip)
                       ));
        }

// EXECUTE GOOGLE GEOCODER QUERY
        if ($gfp = @fopen($googleUrl, 'r'))
        {
            $googleResponse = '';
            while (!feof($gfp)) { $googleResponse .= fgets($gfp); }
            fclose($gfp);
        }
        else
        {
            return FALSE;
        }

// EXTRACT THE DATA
        $gdata    = explode(',',$googleResponse);
        if ($gdata[0] != '200') // RESPONSE CODE SHOULD BE '200' -- IF 602 - BAD ZIP CODE OR UNUSABLE ADDRESS
        {
            return FALSE;
        }
        $this->precision = $gdata[1]; // GEOCODE ACCURACY - ZIP CODE = 5, HIGHER NUMBERS ARE BETTER
        $this->latitude  = $gdata[2];
        $this->longitude = $gdata[3];
        return TRUE;
    } // END function geocodeGoogle
} // END class SimpleGeocoder



// A QUICK AND DIRTY FUNCTION TO MAKE THE OUTPUT SHOW THE PUBLIC INFORMATION ONLY
function print_rr($thing)
{
    $str = print_r($thing, TRUE);
    $arr = explode("\n", $str);
    $num = count($arr) -1;
    foreach ($arr as $ptr => $txt)
    {
        if (preg_match('/:private]/', $txt)) { unset($arr[$ptr]); }
    }
    echo implode("\n", $arr);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kneidelsAuthor Commented:
thanks very much Ray  -for some reason i missed your reply on this till now.

i am using ZIPs, because on the site - we feel its less of a hassle for people to signup with (instead ofn a full address)
.
i usually program in ASP, but will try understand the flow of the code you pasted - many thanks.
if you  have a sample implementation of this it would help me a lot.

thanks again for the advice!
0
Ray PaseurCommented:
"a sample implementation of this" is available on my web site here:
http://www.laprbass.com/RAY_class_SimpleGeoCoder.php

You can install that code and run it on your own server.  It will work just fine with a zip code only, but the precision will (obviously) be less than if you have a full address.

You might also find some examples using ASP if you noodle around the Google Apps site.

Best, ~Ray
0
kneidelsAuthor Commented:
Great , thanks Ray ( i missed the actual HTML part there)

any idea how something like this could work for Canada? i suppose i would need to ask for a city there,  as zip doesn't work?
0
Ray PaseurCommented:
0
kneidelsAuthor Commented:
amazing - thanks Ray!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
GIS/GPS Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.