Code example

The following example searches ZIP Code 80301 for all streets beginning with "A." Note how you can convert a street or segment handle to a range handle for use with GsHandleGet to return Street or Segment information.

/* This example searches ZIP Code 80301 for streets beginning
  with "A" and no specific house number. */
 
char             tempstr[60];
GsStreetHandle   hStreet;
GsSegmentHandle  hSegment;
GsRangeHandle    hRange;
 
/* Use GsFindFirstStreet to get the first street handle that matches the criteria. */
int iStat = GsFindFirstStreet( gs, &hStreet, GS_ZIP_SEARCH, "80301", "A", "" );
while( iStat == GS_SUCCESS )
{
/* We got a valid street handle which we convert to a range handle so that we can use GsHandleGet retrieve information to show the user. Even though we converted to a range handle, it really is still just a street handle, so we can only access those elements that are valid at the street level. See Appendix A for a complete list of valid elements for each handle type. */
hSegment.hStreet = hStreet;
hRange.hSegment = hSegment;
GsHandleGet( gs, GS_PREDIR, &hRange, tempstr, sizeof(tempstr) );
printf( "Street: %s ", tempstr );
GsHandleGet( gs, GS_NAME, &hRange, tempstr, sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_TYPE, &hRange, tempstr, sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_POSTDIR, &hRange, tempstr, sizeof(tempstr) );
printf( "%s\n", tempstr );
 
/* Find the first valid segment for the current street. */
iStat = GsFindFirstSegment( gs, &hSegment );
while( iStat == GS_SUCCESS )
{
/* We’ve got a valid segment, convert to a range handle to get information to display. */
hRange.hSegment = hSegment;
printf( "   Segment: " );
GsHandleGet( gs, GS_BLOCK_LEFT, &hRange, tempstr, sizeof(tempstr) );
   printf( "%s ", tempstr );
GsHandleGet( gs, GS_BLOCK_RIGHT, &hRange, tempstr, sizeof(tempstr) );
   printf( "%s ", tempstr );
GsHandleGet( gs, GS_SEGMENT_PARITY, &hRange, tempstr, sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_SEGMENT_DIRECTION, &hRange, tempstr, sizeof(tempstr) );
printf( "%s \n", tempstr );
      
/* Get the first valid range for the current segment. */
iStat = GsFindFirstRange( gs, &hRange );
while( iStat == GS_SUCCESS )
   {
GsHandleGet( gs, GS_LORANGE, &hRange, tempstr, sizeof(tempstr) );
printf( "      Range: %s ", tempstr );
GsHandleGet( gs, GS_HIRANGE, &hRange, tempstr, sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_BLOCK_LEFT, &hRange, tempstr,sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_PREDIR, &hRange, tempstr,sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_NAME, &hRange, tempstr,sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_TYPE, &hRange, tempstr,         sizeof(tempstr) );
printf( "%s ", tempstr );
GsHandleGet( gs, GS_POSTDIR, &hRange, tempstr, sizeof(tempstr) );
   printf( "%s ", tempstr );
GsHandleGet( gs, GS_ZIP, &hRange, tempstr,         sizeof(tempstr) );
   printf( "%s ", tempstr );
   GsHandleGet( gs, GS_LOUNIT, &hRange, tempstr,sizeof(tempstr) );
   printf( "%s ", tempstr );
   GsHandleGet( gs, GS_HIUNIT, &hRange, tempstr,   sizeof(tempstr) );
   printf( "%s\n", tempstr );
 
   /* Get the next valid range for this segment.*/
   iStat = GsFindNextRange( gs, &hRange );
   }
if ( iStat == GS_ERROR ) break;
 
/* Get the next valid segment for this street. */
iStat = GsFindNextSegment( gs, &hSegment );
}
if ( iStat == GS_ERROR ) break;
 
/* Get the next street that meets the initial criteria. */
iStat = GsFindNextStreet( gs, &hStreet );
}