Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   General Forum (http://www.chiefdelphi.com/forums/forumdisplay.php?f=16)
-   -   FIRST Team Map (http://www.chiefdelphi.com/forums/showthread.php?t=38437)

Timothy D. Ginn 18-06-2005 13:49

Re: FIRST Team Map
 
Quote:

Originally Posted by DarkJedi613
How'd you actually overlay the dots onto the map and get the coords to do it? I was thinking about doing this last week but didn't have a chance (finals...). I was thinking about using Googles APIs (though acutally I was thinking more of one of just displaying dots but being able to view by state/country/region/etc)...so how'd you resolve into coords and then overlay those onto a map?

Also - I'm glad someone is using all the information I pulled off the TIMS system. :)

Great job! :)

I overlayed the dots onto the map using PHP with the GD extension. Getting the geographical coordinates I did by writing a bit of an interface to http://www.multimap.com to use it to resolve them (which would be much easier than doing it through Google, as Google doesn't have APIs for their Maps service as far as I know, and Multimap is quite simple to parse through, I can give more specific details if desired). Once you have the geographical coordinates, it's possible to convert them into pixel coordinates (some detailed instructions are at: http://www.web-max.ca/PHP/ ).

There's also a related thread from a while ago at http://www.chiefdelphi.com/forums/sh...ad.php?t=29199 which does things a different way using Perl rather than PHP and geoinfo files rather than a satellite map (it's US-only as is, though; but you could mix and match ideas from both, if you wanted). If you were to want to do things that way rather than with a satellite map the PEAR Image_GIS package might come in handy: see http://pear.php.net/package/Image_GIS for details.

It's entirely possible to go beyond what either of us have done, though. I think it might be cool to do something like: http://physos.net/~physos/worldwide/test.html (mouse over the points on the map). If you're planning to do that, though; I'd strongly suggest caching the generated map image (since it can take a while). Also, if you're going to make one of these, cache the coordinates for teams, etc. from Multimap (or whatever other one you use); otherwise you're going to end up being way too harsh on the server.

DarkJedi613 18-06-2005 16:53

Re: FIRST Team Map
 
Wow...thanks a lot...

Maybe in the next version of Team Lookup I'll have it generate coordinates and just put it in the file w/ them. :D

I hadn't really looked into Google APIs too much, though I think there is an API for their Map service now...but yeah the way you're saying would be easier.

To get the coordinates did you just feed it into the search engine from multimap then load the entire page as a string using php and search for the x-coord and y-coord or do they have a built in thing to find coordinates?

You just gave me something to play with now! Thanks. :)

The image in this thread is created w/ PHP but they you saved it, correct? As in it doesn't regenerate everytime...

Thanks a lot.

Timothy D. Ginn 18-06-2005 17:45

Re: FIRST Team Map
 
Quote:

Originally Posted by DarkJedi613
Wow...thanks a lot...

Maybe in the next version of Team Lookup I'll have it generate coordinates and just put it in the file w/ them. :D

I hadn't really looked into Google APIs too much, though I think there is an API for their Map service now...but yeah the way you're saying would be easier.

To get the coordinates did you just feed it into the search engine from multimap then load the entire page as a string using php and search for the x-coord and y-coord or do they have a built in thing to find coordinates?

You just gave me something to play with now! Thanks. :)

The image in this thread is created w/ PHP but they you saved it, correct? As in it doesn't regenerate everytime...

Thanks a lot.

I checked the Google API documentation just now and didn't see any mention of an API for Maps. Oh, and yes, I did save the images that I created with PHP; they're not regenerating every time :-)

As for how I did things

For Multimap I wrote (in PHP):

PHP Code:

/*
     *  Returns the geographic coordinates of a particular street address
     *         Return value:
     *         Array(
     *             "lon" = longitude coordinate (decimal #)
     *             "lat" = latitude coordinate (decimal #)
     *             )
     * 
     *     Defaults to no street address, city of Kingston, province of Ontario, country of Canada
     */
    
function getCoordinates($streetaddr ""$city "Kingston"$province "ON"$country "CA") {        
        
// define variable to be used to store coordinate results.
        
$result = array();        

        
// Multimap requires things be trimmed and urlencoded to best match.
        
$streetaddr urlencode(trim($streetaddr));
        
$city urlencode(trim($city));
        
$province urlencode(trim($province));
        
$country urlencode(trim($country));

        
// Try checking database to see if we've already looked this address up
        // (if we have, read it from the database, otherwise query Multimap).
        
$q mysql_query("SELECT longitude, latitude FROM geoLocations WHERE streetAddress='$streetaddr' AND city='$city' AND province='$province' AND country='$country' LIMIT 1;");

        if(
mysql_num_rows($q) == 0) {
            
// Free up the result (to save memory).
            
mysql_free_result($q);
            
            
// Connect to Multimap to retrieve coordinate information
            
$ch curl_init();
            
curl_setopt($chCURLOPT_URL,"http://www.multimap.com/map/places.cgi?client=public&lang=&advanced=&db=" $country "&cname=Great+Britain&overviewmap=&addr2=" $streetaddr "&addr3=" $city "&state=" $province "&pc=");
            
curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
$tmp curl_exec($ch);
            
curl_close($ch);
    
            
// Expand the string into an array so that we can extract longitude and latitude
            
$res explode("&"$tmp);
    
            
// Prepare result to return
            
$result = array("lon" => 0"lat" => 0);
            
$result["lon"] = str_replace("lon="""$res[3]); // longtidude
            
$result["lat"] = str_replace("lat="""$res[4]); // latitude    

            // Enter the coordinates into the database (to save having to query Multimap for them again, later)
            
$q mysql_query("INSERT INTO geoLocations (streetAddress, city, province, country, longitude, latitude) VALUES ('$streetaddr', '$city', '$province', '$country', '" $result["lon"] . "', '" $result["lat"] . "');");        
        } else {
            
// The position is in our database already, so we can look it up from there
            
$res mysql_fetch_object($q);
            
            
// Prepare result to return
            
$result = array("lon" => 0"lat" => 0);
            
$result["lon"] = $res->longitude// longtidude
            
$result["lat"] = $res->latitude// latitude
            
            // Free up the result (to save memory)
            
mysql_free_result($q);
        }
        
// Return result
        
return($result);    
    } 

This caches the results in the database structure:

Code:

CREATE TABLE `geoLocations` (
 `streetAddress` varchar(255) NOT NULL default '',
 `city` varchar(255) NOT NULL default 'Kingston',
 `province` char(2) NOT NULL default 'ON',
 `country` char(2) NOT NULL default 'CA',
 `latitude` decimal(10,4) NOT NULL default '0.0000',
 `longitude` decimal(10,4) NOT NULL default '0.0000'
) TYPE=MyISAM COMMENT='Stores geographical information about addresses'

You may also be interested in this (which in my implementation I put in a class called GeoLocate with the above function)...

Note: The reason it's not a simple typical equation to find distance (eg. ) is mainly that the Earth is (roughly) spherical. For those who care, it's not precisely spherical and therefore the below function is an approximation, but, it seems to me to be more than good enough for all of my purposes:

PHP Code:

/*
     * Returns the distance (in kilometers) between two geographical coordinates
     * 
     * Coordinates are given in the form:
     *         Array(
     *             "lon" = longitude coordinate (decimal #)
     *             "lat" = latitude coordinate (decimal #)
     *         )
     * 
     */
    
function getDistance($position1$position2) {

        
// See: http://jan.ucc.nau.edu/~cvm/latlon_formula.html for an explanation of this formula

        // The formula requires that everything be in radians.  Assumption: The standard coordinates are always in degrees.
        
$a1 deg2rad($position1["lat"]); 
        
$b1 deg2rad($position1["lon"]);
        
$a2 deg2rad($position2["lat"]);
        
$b2 deg2rad($position2["lon"]);
        
        
$r 6371.01// Radius of the Earth (in kilometers)
                     // From: http://ssd.jpl.nasa.gov/phys_props_earth.html

        // Return the distance between the two given points (in kilometers)
        
return acos(cos($a1)*cos($b1)*cos($a2)*cos($b2) + cos($a1)*sin($b1)*cos($a2)*sin($b2) + sin($a1)*sin($a2)) * $r;
    } 

If anyone else wants to use these; that's fine by me, but I'd very much like to hear what you use it for :-) Oh, and if you're going to create derivative works, etc. I'd like a bit of credit. After all, it's fun to play around with things; but it's definitely nice to be acknowledged for producing things that other people find helpful.

Anyway, that should be more than enough to tinker with; have fun :-)

Timothy D. Ginn 29-06-2005 19:27

Re: FIRST Team Map
 
Quote:

Originally Posted by Timothy D. Ginn
I checked the Google API documentation just now and didn't see any mention of an API for Maps. Oh, and yes, I did save the images that I created with PHP; they're not regenerating every time :-)

...

Well, as it turns out earlier today Google released a Maps API:

More information is at:
http://www.betanews.com/article/Goog...ers/1120070538

The Google Maps API itself is documented at:

http://www.google.com/apis/maps/

It's definitely something I'm going to be looking at myself, soon.


All times are GMT -5. The time now is 19:11.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi