Example #1
0
def test_SearchPlace():
    search = SearchPlace(AK, SK)
    allregion = search.listAllRegion()
    assert "北京" in allregion and "广州" in allregion

    query = "银行"
    region = "338"  # 肇庆
    content = search.searchRegion(query=query, region=region, output="json")
    result = json.loads(content)
    assert result["status"] == 0

    content = search.fuzzySearchRegion(query="北京路",
                                       region="广州",
                                       city_limit="false",
                                       output="json")
    result = json.loads(content)
    assert result["status"] == 0

    poi = "银行$酒店"
    location = "23.137903,113.34348"
    content = search.searchCircularArea(query=poi,
                                        location=location,
                                        output="json")
    result = json.loads(content)
    assert result["status"] == 0

    bounds = "23.137903,113.34348,40.063597,116.364973"
    content = search.searchRectangularArea(query=poi,
                                           bounds=bounds,
                                           output="json")
    result = json.loads(content)
    assert result["status"] == 0

    # 测试批量百度坐标查询
    places = {
        "香港": "香港国际机场",
        "广州": "广州白云国际机场",
        "深圳": "深圳宝安国际机场",
        "珠海": "珠海金湾国际机场",
        "澳门": "澳门国际机场",
        "佛山": "佛山沙堤机场",
        "惠州": "惠州平潭机场"
    }
    result = search.queryBatchPlaceCoord(places)
    result = list(result)
    assert len(result) == 7
    assert len(result[0]) == 2

    # 测试 search 方法
    pois = search.search(query, region=region)
    for p in pois:
        assert isinstance(p, POI)
Example #2
0
    "珠海": "珠海金湾国际机场",
    "澳门": "澳门国际机场",
    "佛山": "佛山沙堤机场",
    "惠州": "惠州平潭机场"
}

place = SearchPlace(AK, SK)

dirction = MapDirection(AK, SK)

fw = open("transit_plane_result.csv", "w", encoding="utf-8")
fw.write(
    "origin\t target\t distance\t duration\t price\t vehicle\t description \n")

for name in targets_name:
    pois = place.search(targets_name[name], region=name)
    poi = pois[0]

    loc = poi.get_location()

    for i in origins_data.index:
        obj = TransitObject()
        coords = (round(origins_data["lat"][i],
                        5), round(origins_data["lng"][i], 5))
        # 飞机
        content = dirction.transit(loc,
                                   coords,
                                   tactics_incity=4,
                                   trans_type_intercity=1)
        content = json.loads(content)
        if "status" in content and content["status"] == 0: