【问题标题】:place markers stores(pirtucular store name) with google maps in android在android中使用谷歌地图放置标记商店(虚拟商店名称)
【发布时间】:2018-01-18 10:04:44
【问题描述】:

您好,我想在靠近用户当前位置的所有购物者停止商店上放置标记。我正在使用以下代码

目前我只获得 2 个位置,我想设置一些半径并还想显示所有商店。

    private class GeocoderTask extends AsyncTask<String, Void, List<Address>> {

    @Override
    protected List<Address> doInBackground(String... locationName) {
        // Creating an instance of Geocoder class
        Geocoder geocoder = new Geocoder(getBaseContext());
        List<Address> addresses = null;

        try {
            // Getting a maximum of 3 Address that matches the input text
            addresses = geocoder.getFromLocationName(locationName[0], 10);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return addresses;
    }

    @Override
    protected void onPostExecute(List<Address> addresses) {

        if(addresses==null || addresses.size()==0){
            Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
        }

        // Clears all the existing markers on the map
        googleMap.clear();

        // Adding Markers on Google Map for each matching address
        for(int i=0;i<addresses.size();i++){

            Address address = (Address) addresses.get(i);

            // Creating an instance of GeoPoint, to display in Google Map
            latLng = new LatLng(address.getLatitude(), address.getLongitude());

            String addressText = String.format("%s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                    address.getCountryName());

            markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.title(addressText);

            googleMap.addMarker(markerOptions);

            // Locate the first location
            if(i==0)
                googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
        }
    }
}

但无法获得相关结果。帮帮我。

【问题讨论】:

    标签: android google-maps google-maps-markers android-maps


    【解决方案1】:

    您应该查看 Places API 网络服务的nearby search

    为了让您的生活更轻松,您还可以使用位于 github 的用于 Google 地图服务的 Java 客户端:

    https://github.com/googlemaps/google-maps-services-java

    按照 Java 客户端库的文档,您应该能够搜索附近的地点以获得给定的位置和半径。

    我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 2015-06-02
      • 1970-01-01
      • 2013-09-16
      • 2023-03-28
      相关资源
      最近更新 更多