首页 > 解决方案 > 如何显示选项取决于地区谷歌地图

问题描述

我正在对 Taxi android 应用程序进行一些修改,我想知道如何根据地图或城市上的区域显示Car Type 。- (坐标)

例如:在纽约,我有这些选项(Mini、SUV、miniVan、Limousine),每个选项都有特价。

但是在新球衣中,我只有两个价格不同的选择(Mini,Suv)(例如不像纽约)。

我怎样才能做到这一点 ?

标签: androidgoogle-maps

解决方案


根据坐标你可以找到城市

`      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();
        }`

推荐阅读