我的位置根據其他活動提供的意圖而改變,它工作正常,顯示我想從LatitudeDegree
和LongitudeDegree
獲取的位置。現在我想顯示其附近的地方用戶choice.like如果他鍵入ATM,然後附近的ATM應顯示等。如何從標記位置附近搜索地點?
這是我的代碼,我得到的位置,我試圖使用地方選擇器,但我不知道我是否正確,應該如何使用。
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
private GoogleMap mMap;
private String mAirportName;
private int mLatitudeDegree;
private int mLongitudeDegree;
private int PLACE_PICKER_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Intent newIntent = getIntent();
mAirportName = newIntent.getStringExtra("airportName");
mLatitudeDegree = newIntent.getIntExtra("latDegree", 200);
mLongitudeDegree = newIntent.getIntExtra("lngDegree", 201);
/*PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}*/
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker and move the camera
LatLng latLng = new LatLng(mLatitudeDegree, mLongitudeDegree);
mMap.addMarker(new MarkerOptions().position(latLng).title(mAirportName));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(5));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
}
你有那些項目附近的緯度經度? –
LatitudeDegree和LongitudeDegree不過是我的經緯度 –
如果你想顯示像ATM這樣的其他位置,你還需要那些經緯度 –