【问题标题】:How can I use GoogleMap SDK to list nearby places?如何使用 Google Map SDK 列出附近的地点?
【发布时间】:2019-03-25 05:46:58
【问题描述】:

我正在尝试实现地图活动。我需要使用谷歌地图 SDK 显示附近的地方。我不知道如何使用 Google Map SDK,因为我是初学者。

我尝试了许多使用 HTTP URL 的教程。我需要使用谷歌地图 SDK。使用指定半径的 ATM、BANK 等关键字搜索附近的地方。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    private FusedLocationProviderClient fusedLocationClient;
    double C_Latitude, C_Longitude;
    PlacesClient placesClient;
    private static final int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 1;
    String keyword="atm";
    String radius="1000"; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        Places.initialize(getApplicationContext(),"@string/key");
        placesClient = Places.createClient(this);
        fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {

        mMap = googleMap;
        if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            } else {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_READ_CONTACTS);
            }
        } else {
            fusedLocationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {
                    @Override
                    public void onSuccess(Location location) {
                        if (location != null) {
                            C_Latitude = location.getLatitude();
                            C_Longitude = location.getLongitude();
                            LatLng CurrntLocation = new LatLng(C_Latitude, C_Longitude);
                            CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(CurrntLocation, 19);  //zoom
                            mMap.addMarker(new MarkerOptions().position(CurrntLocation).title("Current Position"));  //marker
                            mMap.animateCamera(yourLocation);
                            GetNearbyPlace();
                        }
                    }
                });
        }
    }

    private void GetNearbyPlace() {

    }
}

【问题讨论】:

    标签: android google-maps google-places-api


    【解决方案1】:

    Google Places SDK 已弃用,请迁移到新的PLACES API

    https://developers.google.com/places/android-sdk/client-migration#place_picker

    • 首先您需要在开发者控制台中启用 PlacesAPI(您应该启用结算帐户)。
    • 然后在您的 gradle 中实现 Places API。

    对于自动填充地点,请遵循以下指南

    https://stackoverflow.com/a/55045772/10579969

    【讨论】:

    • 如何使用它来查找附近的atm、酒店等
    • 兄弟这不是我需要的,在本教程中他使用 HTTP URL 来检索附近的地方。我需要 SDK 来检索附近的地方,这可能吗?
    • 它也使用URL兄弟。我需要在一定半径内使用 sdk find near atm。 sdk有可能吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 2014-11-02
    • 2012-02-22
    相关资源
    最近更新 更多