KRLルールでユーザーの場所を取得するにはどうすればよいですか?
- 方法は何ですか?
- その方法を使用することの長所または短所は何ですか?
これが簡単な例です
rule locations is active {
select using ".*" setting ()
pre {
whereareyou = location:region();
msg = <<
#{whereareyou}
>>;
}
notify("I think you live in", msg) with sticky = true;
}
そして、ここにドキュメントがあります。 http://docs.kynetx.com/docs/Location
ユーザーがプロキシを使用している可能性があるため、IPが実際にはユーザーの実際の場所を表していない場合があるという問題があります。また、ほとんどのISPでは、IPは、任意の時点でIPが使用されている直接の場所ではなく、ISPのハブの場所に登録されます。
ブラウザにhtml5とロケーションAPIが登場したことで、将来、より正確なロケーションを取得できるようになる可能性がありますが、それはまだKRLに実装されていません。
HTM5ブラウザの場所は現在利用可能ですが、それを実現するにはJavaScriptが必要です。これは、ブラウザロケーションAPIを使用する少し古いアプリです。これはおそらくフォームを使用しないように更新される可能性がありますが、ここでは参照用です。
ruleset a8x47 {
meta {
name "WikiNearMe"
description <<
Shows Wikipedia content near the user.
>>
author "TubTeam"
logging off
}
dispatch {
domain "wikipedia.org"
}
global {
datasource placearticles:JSON <- "http://ws.geonames.org/findNearbyWikipediaJSON";
}
rule getlocation is active {
select when pageview "/wiki/" setting ()
pre {
form = <<
<div id="my_div">
<form id="nearmeform" onsubmit="return false" style="display:none;">
<input type="text" name="lat" id="nearmelat"/>
<input type="text" name="lon" id="nearmelon"/>
<input type="submit" value="Submit" />
</form>
<div id="nearmelinks" style="text-align:left;">
<h2>Nearby Links</h2>
</div>
</div>
>>;
}
// notify("Hello World", "This is a sample rule.");
emit <<
navigator.geolocation.getCurrentPosition(function(position){
$K("#nearmelat").val(position.coords.latitude);
$K("#nearmelon").val(position.coords.longitude);
$K("#nearmeform").submit();
//alert("lat: " + position.coords.latitude + " lon: " + position.coords.longitude);
});
>>
{
append("#siteNotice", form);
watch("#nearmeform", "submit");
}
}
rule shownearby is active {
select when web submit "#nearmeform"
foreach datasource:placearticles({"lat":page:param("lat"), "lng":page:param("lon"), "style":"full", "formatted":"true"}).pick("$..geonames") setting (item)
pre {
title = item.pick("$..title");
link = item.pick("$..wikipediaUrl");
}
append("#nearmelinks", "<a href='http://#{link}'>#{title}</a><br/>");
}
}