0

I have an app which returns the road that somebody is on and I would like to find out whether they are on a different road to the one they started on.

For example, I have

userLoc = address.getThoroughfare();

which gets their location and stores it, I would like to store that as a string to something like String firstLoc and then if(userLoc.equals(firstLoc))

Sorry if I was not clear enough, I am asking how to set a String to the first value of userLoc, so I may check it against in the future.

4

1 回答 1

2

我建议使用equalsIgnoreCase(...)而不是 equals 来为自己省去很多麻烦。

基本上,要充实您的代码:

public boolean isStartingRoad(String loc){
 return loc.equalsIgnoreCase(firstLoc);
}

这当然假设您将 firstLoc 保存为同一类中的全局变量。

然后就像这样调用它传递 userLoc 给它

boolean sameroad = isStartingRoad(address.getThoroughfare());

编辑:好的,让我再试一次:

public boolean isStartingRoad(String loc){
     return loc.equalsIgnoreCase(address.getThoroughfare());
    }

基本上可以让您传递当前位置的字符串并进行比较。

于 2013-04-21T22:35:12.310 回答