Javascript error on "Hello World" sample

1 view
Skip to first unread message

ChrisRogers

unread,
Feb 18, 2009, 11:18:30 AM2/18/09
to Loki API
I am trying to get the basic sample API code to work, but instead of
printing my location, I don't see anything.

My error console shows this:

Error: document.getElementById("address") is null

I can use Loki and see the code on the sample site just fine.

What is wrong?

Ryan Sarver

unread,
Feb 18, 2009, 2:33:03 PM2/18/09
to loki...@googlegroups.com
Chris, want to paste all of your code in here so we can see it? that
error would make it look like there isnt an element with an id="address"

ChrisRogers

unread,
Feb 20, 2009, 10:54:39 AM2/20/09
to Loki API
<html><body>

<script type="text/javascript" src="http://loki.com/plugin/files/
loki.js"></script>
<script type="text/javascript">
function init() {
var loki = new LokiAPI();
loki.onSuccess = function(location) {
document.getElementById('address').innerHTML =
location.house_number+' '+location.street+'<br/>'+location.city+',
'+location.region_code+' '+location.postal_code+'<br/
>'+location.latitude+', '+location.longitude;
};
loki.onFailure = function(error, msg){
alert('An error has been encountered ('+error+'). '+msg);
};
loki.setKey('beta');
loki.requestLocation(true,loki.FULL_STREET_ADDRESS_LOOKUP);
}
window.onload = init;
</script>

</body></html>

I just copied/pasted this: http://www.loki.com/why/demoapps/simple

Ryan Sarver

unread,
Feb 20, 2009, 6:46:32 PM2/20/09
to loki...@googlegroups.com
Chris,

The source code is just of the javascript. You need to have a <div
id="address"></div> in the body of the page for the javascript to
populate the address into.

Hope that helps.

Best, Ryan

ChrisRogers

unread,
Feb 24, 2009, 11:29:47 PM2/24/09
to Loki API
Ah, that fixed it. Thanks!
Reply all
Reply to author
Forward
0 new messages