Using KML to update and display an ASP Page

30 views
Skip to first unread message

Shmapdy

unread,
Apr 28, 2008, 8:39:38 PM4/28/08
to KML Developer Support - KML Server Side Scripting
Simply put I have a client computer which is running google earth.
They use a client kml file to contact a server which hosts its portion
of the kml. I would like to be able to take the lat/long of either the
camera location or what the camera is looking at, pass it to the
server and update a web page which will be displayed on the clients
google earth browser. For simplicity the browser will just read back
the lat/long passed to it, from there I can do other devilish stuff.

Suffice it to say I cannot figure out a good way to do it only using
kml which is my ultimate goal. I've tried using NetworkLink, but that
flips out when I don't return a KML. One solution that I can think of
is that the client pass to the server its lat/long and the server
passes back an updated placemark at that lat/long with a html link to
the web page, however this seems like a wasteful solution and
optimally I'd like the page to just display and not have the
placemark. If anyone has any ideas that would be great.

KoflAIR

unread,
Apr 29, 2008, 9:33:00 AM4/29/08
to KML Developer Support - KML Server Side Scripting
The solution to your application will have to consist of two parts.

First part is a network link triggered by OnCameraStop. Every time the
camera stops, google earth calls your network link and by this way
your ASP page that receives GET parameters including the BBOX with lat
long coordinates and other parameters. Have a look at the KML
documentation on Network Links for details. This ASP page can save the
focused coordinates to a database or application array, and has to
return some KML answer to the google earth client. Display a tiny
focus cursor in the middle of the view as feedback for the user eg.

Second part is a web page that works independent from the KML part.
This page can/should poll the coordinates stored by the first script
to find out which content should be displayed. This page has to make
her own autopoll by either META REFRESH tag or by Javascript/AJAX.

There is no way to trigger a webpage update in a browser window by KML.

naptime

unread,
May 12, 2008, 1:37:49 AM5/12/08
to KML Developer Support - KML Server Side Scripting
KoflAIR,

Can you point me to an example page/link on the first part?

I am struggle to get back lat/long values from GE? I look at Network
Links on KML doc, don't see anything.

Thanks.

KoflAIR

unread,
May 15, 2008, 4:56:43 PM5/15/08
to KML Developer Support - KML Server Side Scripting
Check this out.

The KML file being loaded by GE can look like this: (btw it works, the
file being ref'ed exists.)

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<NetworkLink>
<name>Dig hole</name>
<Url>
<href>http://www.koflair.at/earth/dighole.asp?id=500&amp;</href>
<viewRefreshMode>onStop</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Url>
</NetworkLink>
</kml>

In this definition, a Network link is defined that will be reloaded 1
sec after a viewchange in GE stops. GE will automatically add the
parameter BBOX.
When the dighole.asp is called by GE, the following URL will be called
(example):
http://www.koflair.at/earth/dighole.asp?id=500&BBOX=36.55432,14.32324,35.564645,14.268768

The answering file, dighole.asp, may look like this:
<%
Response.ContentType = "application/vnd.google-earth.kml+xml"
s = request.QueryString("BBOX")
bbox = split(s, ",")
west = cdbl(replace(bbox(0),".", ","))
south = cdbl(replace(bbox(1),".", ","))
east = cdbl(replace(bbox(2),".", ","))
north = cdbl(replace(bbox(3),".", ","))
eastwest = ((east - west) / 2) + west
center_lng = formatnumber(eastwest, 8,,,0)
center_lat = formatnumber(((north - south) / 2) + south,8,,,0)
if eastwest > 0 then
eastwest = eastwest - 180
else
eastwest = eastwest + 180
end if
center_lngo = formatnumber(eastwest, 8,,,0)
center_lato = formatnumber(-(((north - south) / 2) + south),8,,,0)
Response.Write "<?xml version='1.0' encoding='UTF-8'?>"
Response.Write "<kml xmlns='http://earth.google.com/kml/2.1'>"
Response.Write _
"<Placemark>" & _
"<name>Dig here (" & replace(center_lng, ",", ".") & "," &
replace(center_lat, ",", ".") & ")</name>" & _
"<description>Ending up at " & replace(center_lngo, ",", ".") & "," &
replace(center_lato, ",", ".") & "</description>" & _
"<Point> <coordinates> " & replace(cdbl(center_lng), ",", ".") & "," &
replace(cdbl(center_lat), ",", ".") & ",5000</coordinates> </Point>" &
_
"<LookAt><longitude>" & replace(cdbl(center_lngo), ",", ".") & "</
longitude><latitude>" & replace(cdbl(center_lato), ",", ".") & "</
latitude></LookAt>" & _
"</Placemark>"
Response.Write "</kml>"
%>

In this example, the id=500 parameter is ignored.
See how the BBOX is split into strings and converted to numbers. Mind
that this script runs on a server with german language, so the decimal
delimiter is ',' instead of '.' so if you run an english server you
may delete the replace functions in those lines like
> west = cdbl(replace(bbox(0),".", ","))

I hope this will help you for the first steps ;-)
Reply all
Reply to author
Forward
0 new messages