Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing a UK Map for a Grid Reference

Status
Not open for further replies.

PatrickHaston

IS-IT--Management
Nov 2, 2001
12
GB
We've developed a little function that others may find useful - no warrenty is supplied with this code, use it at your own risk.

It converts a UK Grid Reference to Eastings and Northings data and calls MultiMap.com to display a map at 1:50,000 of the area around the point (highlighted with a red circle). It can be used for addresses too but we work mainly with Grid References.

It's a very easy function to add to a form and makes you look good. The users here like it.

Patrick.

The first function is added to the WHEN-BUTTON-PRESSED trigger on a button on the form, the other two functions convert the Grid Reference into a format that MultiMap likes better.

declare
V_COMMAND VARCHAR2(2000);
V_NORTHINGS NUMBER;
V_EASTINGS NUMBER;

begin

-- Convert the Grid Reference to Eastings and Northings
V_NORTHINGS := UNF_GRIDREF_NORTH( :GRID_REFERENCE);
V_EASTINGS := UNF_GRIDREF_EAST( :GRID_REFERENCE);

-- Build the command to call Multimap
V_COMMAND := '"c:\program files\internet explorer\IEXPLORE.EXE" || to_char(V_EASTINGS) || '&GridN=' || to_char(V_NORTHINGS) || '&scale=50000'
|| '&title=SNH+Casework+Recording+Location&cat=h';

-- Display the map
host(V_COMMAND);

end;


FUNCTION UNF_GRIDREF_NORTH (P_GRIDREF VARCHAR2) RETURN NUMBER IS
THE_RESULT NUMBER;
TEMP1 INTEGER;
VAR_A INTEGER;
VAR_B INTEGER;

BEGIN
THE_RESULT := 0;
VAR_A := ASCII(UPPER(SUBSTR(P_GRIDREF,1,1))) - 65;
VAR_B := ASCII(UPPER(SUBSTR(P_GRIDREF,2,1))) - 65;

IF VAR_A > 8 THEN
VAR_A := VAR_A - 1;
END IF;

IF VAR_B > 8 THEN
VAR_B := VAR_B - 1;
END IF;

VAR_A := 3 - round(VAR_A / 5);
VAR_B := 4 - round(VAR_B / 5);

TEMP1 := (LENGTH(P_GRIDREF) - 2) / 2;

THE_RESULT := VAR_A * 500000 + VAR_B * 100000 + ((SUBSTR(P_GRIDREF,TEMP1+3,TEMP1)) * 10 ** (5 - TEMP1));

RETURN THE_RESULT;
END;

FUNCTION UNF_GRIDREF_EAST (P_GRIDREF VARCHAR2) RETURN NUMBER IS
THE_RESULT NUMBER;
TEMP1 INTEGER;
VAR_A INTEGER;
VAR_B INTEGER;

BEGIN
THE_RESULT := 0;
VAR_A := ASCII(UPPER(SUBSTR(P_GRIDREF,1,1))) - 65;
VAR_B := ASCII(UPPER(SUBSTR(P_GRIDREF,2,1))) - 65;

IF VAR_A > 8 THEN
VAR_A := VAR_A - 1;
END IF;

IF VAR_B > 8 THEN
VAR_B := VAR_B - 1;
END IF;

VAR_A := MOD(VAR_A, 5) - 2;
VAR_B := MOD(VAR_B, 5);

TEMP1 := (LENGTH(P_GRIDREF) - 2) / 2;

THE_RESULT := VAR_A * 500000 + VAR_B * 100000 + ((SUBSTR(P_GRIDREF,3,TEMP1)) * 10 ** (5 - TEMP1));

RETURN THE_RESULT;
END;
 
That's kinda neat, but using a HOST() command to invoke IE depends on
[ol]
[li]The user having Interet Exploder on their machines and in the directory you specify[/li]
[li]Running the forms Client/Server, as a web-deployed form would display Multimap on the Application Server not the user's machine[/li]
[/ol]
A better solution would be to use the WEB.SHOW_DOCUMENT built-in to display the page thus:
[ignore]
WEB.SHOW_DOCUMENT(' || to_char(V_EASTINGS) || '&GridN=' || to_char(V_NORTHINGS) || '&scale=50000'
|| '&title=SNH+Casework+Recording+Location&cat=h');
[/ignore]

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top