当前位置: 首页>>代码示例>>Python>>正文


Python Location.latlng方法代码示例

本文整理汇总了Python中models.Location.latlng方法的典型用法代码示例。如果您正苦于以下问题:Python Location.latlng方法的具体用法?Python Location.latlng怎么用?Python Location.latlng使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Location的用法示例。


在下文中一共展示了Location.latlng方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: geocode

# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import latlng [as 别名]
def geocode(rawLocation):
    """

    :rtype : Location
    """
    url = "https://maps.googleapis.com/maps/api/geocode/json?address=%s" % rawLocation.replace(" ","+")

    response = urllib2.urlopen(url)
    geocode = json.load(response)
    #debug
    pprint.pprint(geocode)

    location = Location()
    location.status = geocode["status"].encode('utf_8').decode('utf_8')
    if location.status == "OK":
        location.address = geocode["results"][0]["formatted_address"].encode('utf_8').decode('utf_8')
        location.latlng = ndb.GeoPt(geocode["results"][0]["geometry"]["location"]["lat"], geocode["results"][0]["geometry"]["location"]["lng"])
    else:
        location.address = None
        location.latlng = None

    # Debugs
    print "in geocode"
    print (location.status.encode('utf_8') if location.status else None)
    print type(location.status)
    print (location.address.encode('utf_8') if location.address else None)
    print type(location.address)

    return location
开发者ID:qwertyshan,项目名称:Jedi,代码行数:31,代码来源:map.py

示例2: post

# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import latlng [as 别名]
    def post(self):
        messageid = self.request.get("messageid")
        if messageid == "":
            rawCharacter =  cgi.escape(self.request.get("character"), quote = True)
            rawLocation =   cgi.escape(self.request.get("address"), quote = True)
            # Validate character
            (character, charError) = map.validateCharacter(rawCharacter)
            # Validate location
            location = map.validateLocation(rawLocation)
            error, msgError = "", ""

            # Check validation errors and format error message
            if character == None:
                msgChar = rawCharacter
            else:
                msgChar = str(character.name)

            if charError != "":
                error = charError
                msgError = error
            if location.status != "OK":
                error = (error + " " + location.status.encode('utf_8')).decode('utf_8')
                msgError = error
            if (charError == "") and (location.status == "OK"):
                error = ("Move %s to %s. Got it!" % (msgChar, location.address.encode('utf_8'))).decode('utf_8')
                msgError = ""

            print datetime.datetime.utcnow()
            print "error: " + error.encode('utf_8')
            print type(error)
            print "msgError: " + msgError.encode('utf_8')
            print type(msgError)
            # Store in Message store
            if recordMessage("WebForm", None, self.request.remote_addr, msgChar, location, rawCharacter+" "+rawLocation, msgError):
                print "IN APP:"
                top_msgs(True)
                self.writeHTML(error=error, character=character, location=location)
            else:
                error = "App Error: Failed to insert message."
                self.writeHTML(error=error, character=character, location=location)

        else:
            # Validate messageid and get message
            messagekey = ndb.Key(urlsafe=messageid)
            message = Message()
            message = messagekey.get()
            character = Character.query(Character.name == message.character).get()
            location = Location()
            location.address = message.address
            location.latlng = message.latlng

            # If message found
            if not message:
                error = "App Error: Cannot get message."
                self.writeHTML(error=error, character=None, location=None)

            # If message not found
            else:
                # Write
                self.writeHTML(error="", character=character, location=location)
开发者ID:qwertyshan,项目名称:Jedi,代码行数:62,代码来源:main.py

示例3: get

# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import latlng [as 别名]
 def get(self):
     character = Character(name="")
     location = Location()
     location.latlng=ndb.GeoPt(37.7749295, -122.4194155)
     # Write
     self.writeHTML(error="", character=character, location=location)
开发者ID:qwertyshan,项目名称:Jedi,代码行数:8,代码来源:main.py


注:本文中的models.Location.latlng方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。