GSAK (Geocaching Swiss Army Knife)
Contents - Index

GetState (function)

GetState(sOptions) : numeric

This function is a optimized routine to calculate the state name for a given waypoint. Part of this optimization requires that the waypoint must already have a valid country. This function uses polygon files to determine the location of each country and is not guaranteed to be perfect.

sOptions

U = update user data
2 = update user data 2
B = only update if blank or = "nil" or = "none"
F = set user flag, but only if updated
R = set user flag if matching polygon found (see note)
S - Update the state field in the database
A - (abbreviate) update with the 2 or 3 letter (country specific) abbreviated state code rather than the full name.

Note: R option should just be used by itself and was added to allow you to flag those waypoints that have matching polygons without actually updating any data in the database. The B,F and A options should not be used alone and must also include at least one of U,S or 2

Options can be entered in any order. The return value of the function is the number of records changed (that is, where the new  state value is different to the one already on file) - or in the case of the single R option, then number of records flagged

So if you wanted to update the state column with abbreviated names, but only if there wasn't already something in there, the code would be:
 

$updated = GetState("sba")
msgok msg=Number of records updated: $updated

 
There is actually many polygon files required to make this work (even zipped they are many Megabytes in size) so they are not shipped in the GSAK install.

Accordingly the function does a "smart update" of the state polygon files as needed. For the definition of "needed" please see this link

The first time you run this function for a particular state, you must be connected to the Internet so it can download the corresponding polygon files. From then onwards, this function can be run at anytime. 

At the time of writing this help file, countries supported were (More will be added as the Polygon files come to hand):
 

Aland Islands
Algeria
Andorra
Angola
Argentina
Australia
Austria
Belgium
Benin
Bosnia and Herzegovina
Botswana
Brazil
Bulgaria
Burkina Faso
Burundi
Cameroon
Canada
Cape Verde
Central African Republic
Chad
Chile
China
Comoros
Congo
Costa Rica
Cote D'Ivoire
Czech Republic
Democratic Republic of the Congo
Denmark
Djibouti
Ecuador
Egypt
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Faroe Islands
Finland
France
French Southern Territories
Gabon
Gambia
Germany
Ghana
Greece
Greenland
Guinea
Hungary
Iceland
Ireland
Isle of Man
Israel
Italy
Jordan
Kenya
Latvia
Lesotho
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Madagascar
Malawi
Mali
Malta
Mauritania
Mauritius
Montenegro
Morocco
Mozambique
Namibia
Netherlands
New Caledonia
New Zealand
Niger
Nigeria
Norway
Paraguay
Poland
Reunion
Romania
Rwanda
Saint Helena
San Marino
Sao Tome and Principe
Senegal
Sierra Leone
Slovakia
Slovenia
Somalia
South Africa
South Georgia and Sandwich Islands
Spain
Sudan
Swaziland
Sweden
Tanzania
Togo
Tunisia
Turkey
Uganda
United Arab Emirates
United Kingdom
United States
Vanuatu
Western Sahara
Zambia
Zimbabwe

 


Related: GetCounty() GetCountry() GetPolygon() 

Alpha List         Category List
Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact