Android 如何使用邮政编码获取地理位置

Android 如何使用邮政编码获取地理位置,android,geolocation,postal-code,Android,Geolocation,Postal Code,编写一个程序,在该程序中,我必须使用邮政编码显示邻近位置,因此首先,我必须使用用户的邮政编码(用户接受的邮政编码)获取地理位置),然后需要显示该地理位置的邻近位置 我仍然会根据我使用的条件获取用户的当前位置,并从我的JSON中显示附近位置,比如:显示

编写一个程序,在该程序中,我必须使用
邮政编码
显示邻近位置,因此首先,我必须使用用户的邮政编码(用户接受的邮政编码
)获取
地理位置
),然后需要显示该地理位置的邻近位置

我仍然会根据我使用的条件获取用户的
当前位置
,并从我的
JSON
中显示附近位置,比如:显示<2英里
距离内的位置

要获取
当前位置
,我将使用以下方法:

GPSTracker gps;
double latitude, longitude ;

gps = new GPSTracker(LocationsActivity.this);

if(gps.canGetLocation()){

   latitude = gps.getLatitude();
   longitude = gps.getLongitude();

   Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();   

    } else {

    // can't get location
    // GPS or Network is not enabled
    // Ask user to enable GPS/network in settings
    gps.showSettingsAlert();
   }
为了使用用户的当前位置显示
距离<2英里的附近位置
,我使用以下方法:

public void distanceBetweenTwoLocationsfromCurrentLocations() {

            Location currentLocation = new Location("");
            currentLocation.setLatitude(latitude);
            currentLocation.setLongitude(longitude);

            // new arraylist to show nearby places from current location
            ArrayList<Locations> newArrayList = new ArrayList<Locations>();
            for (int i = 0; i < arrayList.size(); i++) {
                locations = (Locations) arrayList.get(i);

                Location destinationLocation = new Location("");
                destinationLocation.setLatitude(Double.valueOf(arrayList.get(i).getLatitude()));
                destinationLocation.setLongitude(Double.valueOf(arrayList.get(i).getLongitude()));

                double inMeters = currentLocation.distanceTo(destinationLocation);
                double inKms = inMeters / 1000;             
                double inMiles = inKms * 0.000621371;

                DecimalFormat df = new DecimalFormat("#.##");
                locations.setDistance(df.format(inMiles));

                if (inMiles < 2) // Comapring Miles whether it is in < 2 miles or not
                    newArrayList.add(locations); // adding near by locations to arraylist
            }

            // Setting adapter again with new list having below 2 mile distance
            adapter = new LocationsAdapter(LocationsActivity.this, R.layout.adapter_locations, newArrayList);
            listview.setAdapter(adapter);
        }
CurrentLocations()的WoLocations之间的公共空白距离{
位置currentLocation=新位置(“”);
currentLocation.setLatitude(纬度);
currentLocation.setLongitude(经度);
//新建arraylist以显示当前位置附近的位置
ArrayList newArrayList=新ArrayList();
对于(int i=0;i
您可以通过两个步骤实现这一点:


  • 希望能有帮助ツ

    您可以通过两个步骤实现这一点:


  • 希望能有帮助ツ

    要查看基于邮政编码的地图,只需将邮政编码填入q参数,然后地图应用程序将处理其余的内容。使用美国和英国邮政编码进行测试

    Uri geoLocation = Uri.parse("geo:0,0?").buildUpon()
                .appendQueryParameter("q", postCode)
                .build();
    Intent mapIntent = new Intent(Intent.ACTION_VIEW);
    mapIntent.setData(geoLocation);
    

    要查看基于邮政编码的地图,只需在q参数中填充邮政编码,然后地图应用程序将处理其余部分。使用美国和英国邮政编码进行测试

    Uri geoLocation = Uri.parse("geo:0,0?").buildUpon()
                .appendQueryParameter("q", postCode)
                .build();
    Intent mapIntent = new Intent(Intent.ACTION_VIEW);
    mapIntent.setData(geoLocation);
    

    检查一下。@SweetWisherヅ 哦。。“那个链接很糟糕,等等,我来了……检查一下。”甜心说ヅ 哦。。那是非常糟糕的链接,等等,我来了。。。