Google Maps Find Nearest Utilities

Вот несколько ошибок в вашем коде, и я переписал код для вас. Вы можете обратиться к комментарию и выполнить тест, чтобы выяснить это.

import random

# two pointers solution, choose the last one as pivot
def partition(nums, left, right, pivot):
    while left < right:
        # here should change < to <=, because if pivot is larger than all in nums[left:right+1], should swap nums[left] with nums[pivot]
        # here I change if to while, because you should traverse the pointer to find the place which is invalid in partition
        while left <= right and nums[left] <= nums[pivot]:
            left += 1
        # here I change if to while, same reason above
        while left < right and nums[right] > nums[pivot]:
            right -= 1
        # you should not use elif here, because you have two ifs, the first if does not work here
        if left < right:
            nums[left], nums[right] = nums[right], nums[left]
    nums[left], nums[pivot] = nums[pivot], nums[left]
    return left


def quicksort(nums, low, high, pivot):
    if low < high:
        pos = partition(nums, low, high, pivot)
        quicksort(nums, low, pos - 2, pos - 1)
        # here is another problem: notice that nums[pivot] is the last element, not the nums[high]
        quicksort(nums, pos + 1, high, high + 1)
    return nums


if __name__ == '__main__':
    for _ in range(100):
        nums = [random.randrange(1, 100) for _ in range(10000)]
        n = len(nums)
        if sorted(nums) != quicksort(nums, 0, n - 2, n - 1):
            print('incorrect')
    print('success')

Я старался изо всех сил, чтобы помочь вам, и надеюсь, вам понравится.

7
задан Juha Syrjälä 7 August 2009 в 15:52
поделиться

2 ответа

Используйте Геокодер HTTP со Смещением Области просмотра (см.: ReverseGeocoding и Смещение Области просмотра) и фильтр результат JSON.

7
ответ дан 7 December 2019 в 03:21
поделиться

Да, это может.

Это объяснено здесь: http://code.google.com/apis/maps/documentation/services.html#LocalSearch

Посмотрите пример здесь: http://code.google.com/apis/maps/documentation/examples/control-googlebar.html

2
ответ дан 7 December 2019 в 03:21
поделиться
Другие вопросы по тегам:

Похожие вопросы: