2008/08/22


APIs for Finding Location

Google launched two APIs for finding the location of a user from a web application. The most simple way, which is also the least precise, is to derive some information about location from the IP. Google AJAX API has an object named google.loader.ClientLocation that includes "metro-level granularity properties": country, region, city, low resolution latitude and longitude. This could be useful if you want to customize a web page for a specific country or to prefill information about location. You probably noticed that google.com automatically redirects to the appropriate international domain and that when you create a Google account your country is already selected.

http://googlesystem.blogspot.com/2008/08/apis-for-finding-location.html

Developer's Guide - Google AJAX APIs - Google Code

When an application makes used of the AJAX API loader, the loader attempts to geo locate the client based on it's IP address. If this process succeeds, the client's location, scoped to the metro level, is made available in the google.loader.ClientLocation property. If the process fails to find a match, this property is set to null.

http://code.google.com/apis/ajax/documentation/#ClientLocation http://code.google.com/apis/gears/api_geolocation.html
試しにやってみたら"google.loader.ClientLocation.address.region"で"「大阪府」って出た。
あと"ClientLocation.latitude"と"ClientLocation.longitude"で緯度経度が得られるので、setCenterで中心位置を変更出来る。
google.load("maps", "2");
google.load("search", "1");
google.setOnLoadCallback(function() {
    var map = new google.maps.Map2(document.getElementById("map"));
    map.setCenter(new google.maps.LatLng(
        google.loader.ClientLocation.latitude,
        google.loader.ClientLocation.longitude), 10);
});
実行結果は以下

続きを読む...

Posted at by




Booで。
class _X:
  s as string

  def constructor():
    s = "ひだまり"

  static def op_LessThan(x as _X, v as string):
    print x.s, v
    return x
 
  static def op_Division(x as _X, v as object):
    if v.GetType() == typeof(int):
      x.s += "スケッチ"
    else:
      x.s += "365"
    return x

X = _X()
_ = 1

X / _ / X < "来週も見てくださいね!"
実行は
C:¥temp> booi yuno.boo
ひだまりスケッチ365 来週も見てくださいね!
でインタプリタ起動するか
C:¥temp> booc yuno.boo
Boo Compiler version 0.8.2.2960 (CLR v2.0.50727.832)

C:¥temp> yuno.exe
ひだまりスケッチ365 来週も見てくださいね!
でコンパイル実行。
boo初めて使ってみたけど、これいいかも。
monoでの実装とかあるのかな?

ちなみにpythonに似てるけど、静的型付けです。あとオペレータの判断順番がpythonと違うので、pythonのまま移植すると「ひだまり365スケッチ 来週も見てくださいね!」になるので要注意

Posted at by



2008/08/19


HTML::TreeBuilderは便利だけど、データ構造がロジックになってしまうのが難点。
Perlでブックオフの店舗を検索し、結果をハッシュの配列に格納する - As a Futurist...

HTMLを解析する練習です。Perlの配列とかハッシュの扱いも少し分かりました。 以下のブックオフの検索をPerlでやっただけです。

http://blog.riywo.com/2008/03/31/164327
ってことでWeb::Scraperで。

#!/usr/bin/perl -w

use strict;
use warnings;
use URI;
use Web::Scraper;
use YAML;

my $str = shift || '新宿';
my $uri = URI->new( 'http://www.bookoff.co.jp/shop/shop.php' );
$uri->query_form(
    action => 'search',
    station => $str,
    shop_name => $str,
);

warn Dump scraper {
    process '//tr[td]', 'res[]' => scraper {
        process '//td[1]', name => 'TEXT',
        process '//td[2]', time => 'TEXT',
        process '//td[3]', tel => 'TEXT',
        process '//td[4]', place => 'TEXT',
    };
    result qw/res /;
}->scrape( $uri );
Web::Scraper便利。
process書かずに
name => '//td[1]/text()'
とか書けるシンタックスシュガーあったらなぁ...とか思った。
Posted at by