代码之家  ›  专栏  ›  技术社区  ›  ABDALRAHMAN MOLOOD

如何显示选项取决于谷歌地图的区域

  •  0
  • ABDALRAHMAN MOLOOD  · 技术社区  · 6 年前

    我正在为出租车Android应用程序做一些修改,我想知道如何显示 汽车类型 取决于地图或城市上的区域。- (坐标)

    例如: 在纽约,我有这些选择(迷你车,SUV,小面包车,豪华轿车),每个都有特别的价格。

    但是 在新泽西州,我只有两种选择(迷你,SUV),价格不同(比如不像纽约)。

    我该怎么做?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Siddhesh Golatkar    6 年前

    根据坐标,你可以找到这个城市

    `      try {
                Geocoder geocoder;
                String city=null;
                List<Address> yourAddresses;
                geocoder = new Geocoder(this, Locale.getDefault());
                yourAddresses = geocoder.getFromLocation(yourLatitude, yourLongitude, 1);
    
    
            final String yourAddress = yourAddresses.get(0).getAddressLine(0);
            if (yourAddresses != null && yourAddresses.size() > 0) {
                android.location.Address address = yourAddresses.get(0);
                @SuppressWarnings("MismatchedQueryAndUpdateOfStringBuilder") StringBuilder sb = new StringBuilder();
                for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                    sb.append(address.getAddressLine(i)).append("\n");
                }
                city = address.getLocality();
                Log.d("city", "onCreate: "+city);
            }
    
            } catch (IOException e) {
                e.printStackTrace();
            }`