我正在使用Android studio
并尝试创建使用Google Maps V2
的应用程序。我使用API Key
使地图运行良好。
我将向markers
添加几个map
。我想以这样的方式添加markers
,只有当他们位于当前radius
用户的特定location
时才会添加marker
。是否有任何方法可以检查radius
是否包含在radius
中?我们如何为地图添加import random
def game():
# Generate a random number between 1-100 and initiate repeat guess list
secret_num=random.randint(1,10)
# Initiate duplicate list
# Consider using a set instead so you don't have to cast it into a set later
already_guesses = []
while True:
# Ask for user guess
guess = int(input('Guess a number from 1-10> '))
# Help with guesses and announce if it is correct number!
# Catch someone if they submit the same number
if guess in already_guesses:
print ("You already guessed that number, try again")
elif guess == secret_num:
# Format your strings properly
print("whooohoo! you guessed it, my number is {0}".format(secret_num))
# See how many unique guesses there were and add the correct guess to it (+1)
# To do so just use a set
print("It took you {0} guesses".format(
len(set(already_guesses))+1
))
break
elif guess < secret_num:
print("You\'re getting hot, try a higher number")
else:
guess > secret_num
print("You\'re cold, try a lower number")
# Make sure to append the guess to the already_guessed list in any case, not just if the number is in already_guesses
# If you only do that in your original if block, already_guesses will always remain empty
already_guesses.append(guess)
# Ask if they want to play again
play_again = input("Do you wanna play again? y/n")
if play_again != 'n':
game()
else:
print("Bah Bye!")
game()
?
答案 0 :(得分:1)
如果有人徘徊,我就是这样做的。 Location中有一个名为distanceBetween()的方法。 这是该方法的文档。您可能会发现distanceTo()也很有用。 http://developer.android.com/reference/android/location/Location.html 向下滚动以找到方法。
答案 1 :(得分:1)
您也可以使用:
GOOD_CHARS = ('a'..'z').to_a.join << "'-"
#=> "abcdefghijklmnopqrstuvwxyz'-"
def validate(str)
return false if str.empty? || (str[0]==' ' || str[-1]==' ')
nbr_spaces = str.count(' ')
return false if nbr_spaces > 2
str.downcase.count(GOOD_CHARS) + nbr_spaces == str.size
end
validate "a B-' v" #=> true
validate "aB-'v" #=> true
validate "aB-`1v" #=> false
validate "a B-'1 v" #=> false
validate " a B-'1v" #=> false
这将检查LatLngBounds bounds = googleMap.getProjection().getVisibleRegion().latLngBounds;
bounds.contains(your_bounds)
your_bounds
是否被联合起来