Example #1
0
 def _getPayload(self, origin, destination, **kwargs):
     orig = common.convertCoord(origin)
     dest = common.convertCoord(destination)
     payload = {
         "origin": orig,
         "destination": dest,
         "ak": self.ak,
         "timestamp": int(time.time())
     }
     if kwargs:
         payload.update(kwargs)
     return payload
Example #2
0
    def geoDecode(self, location, latest_admin_data=1, **kwargs):
        '''
        
        Parameters:

            location : string or tuple, for exmaple: "38.76623,116.43213",

            latest_admin : int, Whether this parameter can access the latest data, 1 means use lastest 
            administrative area data, 0 will not.
                    
        Returns:

            content: string, the content of get from baidu API

        site: http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding
        '''
        urlPath = "/geocoder/v2/"
        location = common.convertCoord(location)
        payload = {
            "location": location,
            "latest_admin": latest_admin_data,
            "ak": self.ak,
            "timestamp": int(time.time())
        }
        if kwargs:
            payload.update(kwargs)
        content = self.encry.get(HOST, urlPath, payload)
        print("geo-decode URL: ", self.encry.url)
        return content
Example #3
0
    def searchCircularArea(self, query, location, **kwargs):
        '''
        search POI with the circular area, you provide the coordinate of center.
        
        parameter:

            query : string, separate with `$` , for exmaple: "银行$酒店",

            location : string, include "latitude,longitude", 
            for exmaple: guangzhou coordinate value is "23.137903,113.34348",

        Returns:

            content: string, the content of get from baidu API

        site: http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-placeapi
        '''
        urlPath = "/place/v2/search"
        payload = self._getPayload(query, **kwargs)
        location = common.convertCoord(location)
        payload["location"] = location
        content = self.encry.get(HOST, urlPath, payload)
        print("search circular area URL: ", self.encry.url)
        return content
Example #4
0
def test_convertCoord():
    coord = convertCoord("12.32323,56.23422")
    assert coord == "12.32323,56.23422"
    coord = convertCoord((12.32323,56.23422))
    assert coord == "12.32323,56.23422"