Home
Legal Land Converter for Android
API for Legal Land Converter
Links
Sitemap

API for Legal Land Converter


Example Query Strings

GPS USA

GPS CANADA

LEGAL CANADA

PLSS USA

NTS

Lat/Long to USNG/MGRS Only

'View Source' to see how to build the query string

'Click' the links to run the conversion and see the results returned.


Query Sent

http://legallandconverter.com/cgi-bin/android2016.cgi?username=USERNAME&password=PASSWORD&quarter=SW&section=24&township=12&range=20&meridian=4&cmd=legal

Please change USERNAME and PASSWORD to the username and password for you account.

Text Returned


Content-type: text/plain

STATUSBAR: Version 1.20 Available
LATITUDE: 50.008196
LONGITUDE: -112.614401
UTM: 12N 384323 5540791
MGRS: 12UUA8432240790
NTS: D-10-A/82-I-2
CREDITS: 29
LSD: 
QUARTER: SW
QUARTERLSD: SW
USAQUARTER: 
USASECTION: 
USATOWNSHIP: 
USANORTHSOUTH: 
USARANGE: 
USAEASTWEST: 
USAMERIDIAN: 
USASTATE: 
COUNTRY: Canada
HAVECONVERSION: 1

Query String for Latitude and Longitude

http://legallandconverter.com/cgi-bin/android2016.cgi?username=DEVELOPX&password=TEST1234&latitude=48.00820&longitude=-112.61440&cmd=gps

Text Returned


STATUSBAR: Version 4.00 Available
USAQUARTER: NE
USASECTION: 15
USATOWNSHIP: 26
USANORTHSOUTH: N
USARANGE: 8
USAEASTWEST: W
USAMERIDIAN: Principal
USASTATE: MT
COUNTRY: USA
LSD: 
QUARTER: 
QUARTERLSD: 
SECTION: 
TOWNSHIP: 
RANGE: 
EASTWEST: 
MERIDIAN: 
RURALUNIT: 
RURALHOUSE: 
RURALTYPE: 
RURALACCESS: 
MAPQUARTER: D
MAPUNIT: 10
MAPBLOCK: A
MAPSERIES: 82
MAPAREA: A
MAPSHEET: 2
UTM: 12N 379594 5318473
MGRS: 12U UU 79593 18472
CREDITS: 85
HAVECONVERSION: 1

Apache Java Libraries

Apache Java Library Documentation

Apache Java Library Download


Java Libraries


   import org.apache.http.HttpResponse;
   import org.apache.http.NameValuePair;
   import org.apache.http.client.HttpClient;
   import org.apache.http.client.entity.UrlEncodedFormEntity;
   import org.apache.http.client.methods.HttpPost;
   import org.apache.http.impl.client.DefaultHttpClient;
   import org.apache.http.message.BasicNameValuePair;
   

Resource Strings

   
   <string name="url">http://legallandconverter.com/cgi-bin/android2016.cgi</string>
   <string name="version">1.20</string>
   

Query Variables

  
   // GPS

   String latitudevalue   = "";
   String longitudevalue  = "";
   String altitudevalue   = "";
   String accuracyvalue   = "";

   // LEGAL LAND CANADA

   String quarterlsdvalue = "";
   String lsdvalue        = "";
   String quartervalue    = "";
   String sectionvalue    = "";
   String townshipvalue   = "";
   String rangevalue      = "";
   String eastwestvalue   = "";
   String meridianvalue   = "";

   // LEGAL LAND USA

   String usaquartervalue    = "";
   String usasectionvalue    = "";
   String usatownshipvalue   = "";
   String usanorthsouthvalue = "";
   String usarangevalue      = "";
   String usaeastwestvalue   = "";
   String usameridianvalue   = "";
   String usastatevalue      = "";


   
   // Conversion Returned: CANADA or USA
   
   String countryvalue    = "";
   
   

   // COMPOSITES

   String ntsvalue        = "";
   String utmvalue        = "";

   // ACCOUNTING

   String creditsvalue    = "";
   String statusbarvalue  = "";


   // FLAGS

   public int haveconversion = 0;
   public int havegps = 0;

  

Clear Variables

           
   public void ClearResults() 
   {
      latitudevalue = "";
      longitudevalue = "";
      altitudevalue = "";
      accuracyvalue = "";

      lsdvalue = "";
      quarterlsdvalue = "";
      quartervalue = "";
      sectionvalue = "";
      townshipvalue = "";
      rangevalue = "";
      eastwestvalue = "";
      meridianvalue = "";
      
      usaquartervalue = "";
      usasectionvalue = "";
      usatownshipvalue = "";
      usanorthsouthvalue = "";
      usarangevalue = "";
      usaeastwestvalue = "";
      usameridianvalue = "";
      usastatevalue = "";
      
      countryvalue = "";

      ntsvalue = "";
      utmvalue = "";

      creditsvalue = "";
      statusbarvalue = "";

      haveconversion = 0;
      havegps = 0;
      
   }
        
      
  

Build Query and Make Request

       
   public void ContactMothership()
   {
       String version = getResources().getString(R.string.version);
       String url = getResources().getString(R.string.url);
       HttpClient client = new DefaultHttpClient();
       HttpPost   post   = new HttpPost(url);
       try {

          String line = "";                  
          List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
          nameValuePairs.add(new BasicNameValuePair("version",version));
          nameValuePairs.add(new BasicNameValuePair("cmd","legal"));
          nameValuePairs.add(new BasicNameValuePair("username",usernamevalue));
          nameValuePairs.add(new BasicNameValuePair("password",passwordvalue));
          nameValuePairs.add(new BasicNameValuePair("quarter", quarterlsdvalue));
          nameValuePairs.add(new BasicNameValuePair("section", sectionvalue));
          nameValuePairs.add(new BasicNameValuePair("township",townshipvalue));
          nameValuePairs.add(new BasicNameValuePair("range",   rangevalue));
          nameValuePairs.add(new BasicNameValuePair("meridian",meridianvalue));

          post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

          handler.sendEmptyMessage(EXECUTE);
           
          HttpResponse response = client.execute(post);
          
          BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()),8192);
                    
          while ((line = rd.readLine()) != null) 
          {
             ParseLine(line);               
          }
          handler.sendEmptyMessage(FINISH);
       }       
       catch (Exception e) 
       {
         statusbarvalue = e.getMessage();
         handler.sendEmptyMessage(FUBAR);
       }
   }

Parse Results into Java Variables

  
     public void ParseLine(String line) 
     {

      if (line.startsWith("HAVECONVERSION:")) {
         haveconversion = 1;
         return;
      }
      if (line.startsWith("HAVEGPS:")) {
         havegps = 1;
         return ;
      }
      
      // GPS

      if (line.startsWith("LATITUDE:")) {
         latitudevalue = line.substring(10);
         return;
      }
      if (line.startsWith("LONGITUDE:")) {
         longitudevalue = line.substring(11);
         return;
      } 
      if (line.startsWith("ALTITUDE:")) {
         altitudevalue = line.substring(10);
         return;
      } 
      if (line.startsWith("ACCURACY:")) {
         accuracyvalue = line.substring(10);
         return;
      }
      
      // LEGAL LAND CANADA

      if (line.startsWith("QUARTERLSD:")) {
         quarterlsdvalue = line.substring(12);
         return;
      }
      if (line.startsWith("LSD:")) {
         lsdvalue = line.substring(5);
         return;
      }
      if (line.startsWith("QUARTER:")) {
         quartervalue = line.substring(9);
         return;
      }
      if (line.startsWith("SECTION:")) {
         sectionvalue = line.substring(9);
         return;
      }
      if (line.startsWith("TOWNSHIP:")) {
         townshipvalue = line.substring(10);
         return;
      }
      if (line.startsWith("RANGE:")) {
         rangevalue = line.substring(7);
         return;
      }
      if (line.startsWith("EASTWEST:")) {
         eastwestvalue = line.substring(10);
         return;
      }
      if (line.startsWith("MERIDIAN:")) {
         meridianvalue = line.substring(10);
         return;
      }
      

      // LEGAL LAND USA

      if (line.startsWith("USAQUARTER:")) {
         usaquartervalue = line.substring(12);
         return;
      }
      if (line.startsWith("USASECTION:")) {
         usasectionvalue = line.substring(12);
         return;
      }
      if (line.startsWith("USATOWNSHIP:")) {
         usatownshipvalue = line.substring(13);
         return;
      }
      if (line.startsWith("USANORTHSOUTH:")) {
         usanorthsouthvalue = line.substring(15);
         return;
      }
      if (line.startsWith("USARANGE:")) {
         usarangevalue = line.substring(10);
         return;
      }
      if (line.startsWith("USAEASTWEST:")) {
         usaeastwestvalue = line.substring(13);
         return;
      }
      if (line.startsWith("USAMERIDIAN:")) {
         usameridianvalue = line.substring(13);
         return;
      }
      if (line.startsWith("USASTATE:")) {
         usastatevalue = line.substring(10);
         return;
      }
      
      
      // COUNTRY
      
      if (line.startsWith("COUNTRY:")) {
         countryvalue = line.substring(9);
         return;
      }
      
      
      
      // COMPOSITES

      if (line.startsWith("NTS:")) {
         ntsvalue = line.substring(5);
         return;
      }
      if (line.startsWith("UTM:")) {
         utmvalue = line.substring(5);
         return;
      }
      if (line.startsWith("MGRS:")) {
         mgrsvalue = line.substring(6);
         return;
      }
      
      // ACCOUNTING
      
      if (line.startsWith("CREDITS:")) {
         creditsvalue = line.substring(9);
         return;
      }
      if (line.startsWith("STATUSBAR:")) {
         statusbarvalue = line.substring(11);
         return;
      }

      // STATUS MESSAGE / CONVERSION ERROR MESSAGE FROM SERVER
      
      if (line.contains("():")) 
      {
         int ix = line.indexOf(":");
         if (ix != -1 && ix < (line.length() - 2)) 
         {
            statusbarvalue = line.substring(ix + 2);
         }
      }
         
   }

See the Android Manual For More Help

Android Manual


www.legallandconverter.com
Legal Land Converter
Phone: 780.455.7226
contact@legallandconverter.com
Copyright © 2017