在android中使用谷歌地图放置标记商店(pirtucular商店名称)

在android中使用谷歌地图放置标记商店(pirtucular商店名称),android,google-maps,google-maps-markers,android-maps,Android,Google Maps,Google Maps Markers,Android Maps,嗨,我想在所有靠近用户当前位置的购物者站点商店上放置标记。我正在使用以下代码 目前我只得到2个位置,我想设置一些半径,并希望显示所有的商店也 private class GeocoderTask extends AsyncTask<String, Void, List<Address>> { @Override protected List<Address> doInBackground(String... locationName)

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

目前我只得到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));
        }
    }
}
私有类GeocoderTask扩展异步任务{
@凌驾
受保护列表doInBackground(字符串…位置名称){
//创建Geocoder类的实例
Geocoder Geocoder=新的Geocoder(getBaseContext());
列表地址=空;
试一试{
//获取最多3个与输入文本匹配的地址
addresses=geocoder.getFromLocationName(locationName[0],10);
}捕获(IOE异常){
e、 printStackTrace();
}
返回地址;
}
@凌驾
受保护的void onPostExecute(列表地址){
if(addresses==null | | addresses.size()==0){
Toast.makeText(getBaseContext(),“找不到位置”,Toast.LENGTH_SHORT.show();
}
//清除地图上的所有现有标记
googleMap.clear();
//在谷歌地图上为每个匹配地址添加标记
对于(int i=0;i 0?地址。getAddressLine(0):“”,
address.getCountryName());
markerOptions=新的markerOptions();
标记选项位置(板条);
标记选项。标题(地址文本);
googleMap.addMarker(markerOptions);
//找到第一个位置
如果(i==0)
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
}
但无法得到相关结果。帮帮我。

您应该看看Places API web服务

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

遵循Java客户机库的文档,您应该能够在附近的地方搜索给定的位置和半径

我希望这有帮助