小编joe*_*guy的帖子

缩小地理编码器地址仅限于城市

我有一个地理编码器,gcd和这行代码反向地理编码

List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1);
                    if(addresses != null) {
                        Address returnedAddress = addresses.get(0);

                        for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
                       strReturnedAddress = (returnedAddress.getAddressLine(i)).toString();
Run Code Online (Sandbox Code Playgroud)

strReturnedAddress返回类似的东西

10453 Central Bronx,New York City,NY

我只需要城市名称,即纽约市.

删除部分字符串将非常困难,因为地理编码的输出可能会发生变化.我只需要地理编码给我这个城市.

我查了http://developer.android.com/reference/android/location/Geocoder.html但找不到答案.

android reverse-geocoding

3
推荐指数
1
解决办法
2457
查看次数

如何使用正则表达式来取出特定的单词?

我希望从字符串中删除"是",但如果字符串是,请说

"同位素与物理有关,物理学很有趣"

我只想要替换"is"这个词而不是同位素中的"is".

我可以用

.replaceAll(" is", "")
.replaceAll("is ", "")
Run Code Online (Sandbox Code Playgroud)

但我想用正则表达式来完成这个以供将来参考.

.replaceAll("是"),"")会起作用吗?

谢谢.

java regex

1
推荐指数
1
解决办法
63
查看次数

为什么不替换这行代码中的所有工作?

    String weatherLocation = weatherLoc[1].toString();
weatherLocation.replaceAll("how","");
weatherLocation.replaceAll("weather", "");
weatherLocation.replaceAll("like", "");
weatherLocation.replaceAll("in", "");
weatherLocation.replaceAll("at", "");
weatherLocation.replaceAll("around", "");
test.setText(weatherLocation);
Run Code Online (Sandbox Code Playgroud)

weatherLocation仍然包含"喜欢"

java string

0
推荐指数
2
解决办法
1468
查看次数

无法使用地理编码器,未处理的类型为IOException

这是代码

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
                Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                double longitude = location.getLongitude();
                double latitude = location.getLatitude();
                Geocoder gcd = new Geocoder(context, Locale.getDefault());
                List<Address> addresses = **gcd.getFromLocation(latitude, longitude, 1);**
Run Code Online (Sandbox Code Playgroud)

出现错误的部分用星号突出显示。

谢谢。

android

0
推荐指数
1
解决办法
1677
查看次数

标签 统计

android ×2

java ×2

regex ×1

reverse-geocoding ×1

string ×1