Showing posts with label google. Show all posts
Showing posts with label google. Show all posts

October 11, 2008

A custom widgets for GeoPt Property

I attended a Maps API hack-a-thon in Tokyo. There I wrote some utility class which helps us to handle GeoPt Property very easy.

In this article, I'll show you some sample code which store geopoint data by just clicking on Google Map. Before we go, perhaps you can read the djangoforms documentation. This will help you to understand the codes in this article.

Please create a directory for this article, copy my_geopt.py to the directory and create 3 brand new files app.yaml, main.py, and index.html. That's all.

After creating these files, start local dev server, get access to localhost, and see that you can specify a particular GeoPt by just clicking on the Google Map.

And here is a live demo(slightly more complicated, but basically almost the same).

Happy coding :-)

app.yaml
application: geotest
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: main.py


main.py
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import os
import wsgiref.handlers

from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.ext.db import djangoforms
import my_geopt

class Place(db.Model):
  name = db.StringProperty()
  description = db.StringProperty()
  geopoint = db.GeoPtProperty()
  date = db.DateTimeProperty(auto_now=True)

class PlaceForm(djangoforms.ModelForm):
  class Meta:
    model = Place

class MainPage(webapp.RequestHandler):
  def post(self):
    data = PlaceForm(data=self.request.POST)
    if data.is_valid():
      # Save the data, and redirect to the view page
      entity = data.save(commit=False)
      entity.put()
      self.redirect('/')
    else:
      # Reprint the form
      contents = {'form': data}
      path = os.path.join(os.path.dirname(__file__), 'index.html')
      self.response.out.write(template.render(path, contents))
  def get(self):
    contents = {'form': PlaceForm()}
    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, contents))

application = webapp.WSGIApplication(
  [('/', MainPage),],
  debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()


index.html (Please replace 2 YOURAPIKEYs with your Maps API Key)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GeoPtWidgets Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=YOURAPIKEY"
type="text/javascript"></script>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=YOURAPIKEY"
type="text/javascript"></script>
<script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js"
type="text/javascript"></script>
<style type="text/css">
@import url("http://www.google.com/uds/css/gsearch.css");
@import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
</style>
</head>

<body onunload="GUnload()">
<h1>GeoPtWidgets Example</h1>
<form method="post" action="/">
{{ form.as_p }}
<input type="submit" value="register"/>
</form>
</body> </html>

June 1, 2008

My first app on App Engine

I attended the conference named 'Google I/O'. It was a very exciting event for an engineer like me. I attended many sessions that were, in most cases, related to Google App Engine.

Google App Engine is a web platform where we can run our web application programs on Google's infrastructure. In my opinion, that could be the biggest paradigm shift this decade.

In those sessions, I learned many techniques about how to build applications on Google App Engine, so I finally wrote up my first application on App Engine called 'InterNovel'. The URL is below.

http://internovel.appspot.com/

In this application, there are novels. Each novel has its own state. The state is one of the following three: 1. Accepting fragments. 2. Votes. 3. Complete.

1. Accepting fragments
When the novel is in this state, everyone can post a continuous fragment. If the number of posted fragments reaches a particular count (that the owner of the novel decided beforehand), the state will change to 2.

2. Votes
When the novel is in Votes state, everyone can vote on their favorite fragments among the candidates. If the total number of the votes reaches a particular count (this number is also editable by the owner), the state will change to 1 or 3.

3. Complete
If the number of iterations between states 1 and 2 reaches a particular number, the completion comes. The state will never change from this time.

Well, that's all about this application. Isn't it interesting?

May 30, 2008

Google I/O が終わりました

終わってしまいました。 Guido のセッションがものすごく High Level だったのが意外でした。 High Level というのは 「 core では無い」という意味ですが。

全体的な感想ですが、今回は主な興味の対象である App Engine のセッションを中心に見てきまして、 App Engine についていろいろあやふやだった点がはっきりしてきました。とても有意義なセッション達でした。

ところで今回同行した a2c さんが面白い亊を言っていました。興味の無いテクノロジーのセッションを聞くのも意外と楽しい...と。そういうものかもしれません。発見する亊はそもそも楽しいですからね。

そうそう。以前のポストで書いた App Engine 用のソフトウェアがだいたい完成しましたので、URL を書いときます。
http://internovel.appspot.com/

まだ説明とか全然足りないので、多分正体や使い方も皆目分からないと思います。それらは日本に帰ってからおいおい書くつもりです。

今日はとりあえずこんなところで。

May 25, 2008

Google I/O前夜

Google I/O が近づいて来ましたので準備をはじめました。まずはプログラムのスケジュールをダウンロードして印刷しておきます。これを飛行機の中で眺めておけば、参加したいプログラムをある程度しぼれるでしょう。荷物は少なめです。いつも使っているトラベルバッグに収まりそう。

Google I/O 自体は 5/28, 5/29 の2日間なのですが、私自身は 5/27 のうちに San Francisco に到着予定です。この日の夕食をどうするか悩んでいたのですが、何人かの Googler がホストしてくれる亊になったので気が楽になりました :-)

私個人として、今一番注目しているテクノロジーは App Engine です。Google のインフラを使って Web アプリが動かせるのですから、冗長化の面でもスケーラビリティの面でも大きなメリットがあります。それに python だし。 python は私のお気に入りです。

そうそう。まだ内容は内緒ですが、 App Engine で動く Web アプリを作っている最中なのです。もう少しでプロトタイプが完成しそうなので、飛行機の中で書き終えられたら良いなと思っています。とりあえず動くものが完成したら App Engine Group にポストしてみるつもりです。(5/26追記) グループにポストするよりも Applications Gallery に登録する方が良さそうですね。