我正在尝试实施Map活动。我需要使用Google Map SDK显示附近的地方。我是个初学者,所以我不知道如何使用Google Map SDK。
我尝试了许多教程,所有教程都使用HTTP URL。我需要使用Google Map 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() {
}
}
答案 0 :(得分:1)
已弃用Google Places SDK,请迁移到新的 PLACES API
https://developers.google.com/places/android-sdk/client-migration#place_picker
对于自动填充位置,请遵循以下准则