我正在尝试在我的GAE应用中使用Google Map API,但无法按照我希望的方式制作它。我试图使用gecoding-simple的代码示例 http://code.google.com/intl/en/apis/maps/documentation/javascript/examples/geocoding-simple.html
我正在尝试显示我的事件发生地点的地图,该地图来自
class Event(db.Model):
title = db.StringProperty(required=True)
description = db.TextProperty()
time = db.DateTimeProperty()
location = db.PostalAddressProperty()
creator = db.UserProperty()
edit_link = db.TextProperty()
gcal_event_link = db.TextProperty()
gcal_event_xml = db.TextProperty()
hobby = db.ReferenceProperty(Hobby)
我希望将标记放在Event.location
,而不是将文本字段和类型放在标记所在的位置。var address = {{event.location}};
geocoder.geocode( { 'address': address}, function(results, status)
我已将var address = document.getElementById(“address”)。value更改为{{event.location}} 以为这就是我必须要做的......但它不起作用......
我该怎么做...我在哪里更改示例代码。
事件在以下类中创建。
class CreateEvent(BasePage):
title = 'Create!'
def get(self):
"""Show the event creation form"""
self.write_page_header()
template_values = {}
path = os.path.join(os.path.dirname(__file__), 'templates')
path = os.path.join(path, 'create.html')
self.response.out.write(template.render(path, template_values))
self.write_page_footer()
def post(self):
"""Create an event and store it in the datastore.
This event does not exist in Google Calendar. The event creator can add it
to Google Calendar on the 'events' page.
"""
self.write_page_header()
if self.request.get("hobby"):
hobby_name = self.request.get('hobby')
new_hobby = Hobby(name=hobby_name.strip(), key_name = hobby_name.strip())
# Create an event in the datastore.
new_event = Event(title=self.request.get('name'),
creator=users.get_current_user(),
# Take the time string passing in by JavaScript in the
# form and convert to a datetime object.
time=datetime.datetime.strptime(
self.request.get('datetimestamp'), '%d/%m/%Y %H:%M'),
description=self.request.get('description'),
location=self.request.get('location'),
hobby = new_hobby)
new_event.put()
info.html是以下
<h1 id="header">Event Info</h1>
<p>Name: {{event.title|escape}}</p>
<p>Description: {{event.description|escape}}</p>
<p>Location: {{event.location|escape}}</p>
<p>Attendee: {{event.attendee.email|escape}}</p>
<p>When: {{event.time}} (UTC)</p>
{% for greeting in greetings %}
{% if greeting.author %}
<b>{{ greeting.author.nickname }}</b> wrote:
{% else %}
An anonymous person wrote:
{% endif %}
<blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Write on the Wall"></div>
</form>
google map API follows here.
提前完成。
答案 0 :(得分:0)
var address = 'London';
geocoder.geocode({ 'address': address }, function (results, status)
似乎在我这边工作得很好。 你有任何错误吗?
为什么你的event.location是用双括号框起来的? 也许这会导致问题?