I want to save user form information with location field. For location I want to open google map on some button click and location to be selected when user click on location over map and post-filled location into form.
I found place picker as related solution, So I have used Place Picker Google API and I am able to open google map, when I move arrow over preferred location and click on Select this location (Appearing black color with now coordinates showing under that).
Confirmation box opens with 2 option :
1.) Change location
2.) Select (Disabled mode)
I want to select anonymous location and return to main activity.
Below is my code :
private TextView get_place;
int PLACE_PICKER_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
get_place = (TextView)findViewById(R.id.textView1);
get_place.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Intent intent;
try {
intent = builder.build(getApplicationContext());
startActivityForResult(intent,PLACE_PICKER_REQUEST );
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
protected void onActivityResult( int requestCode , int resultCode , Intent data ){
if( requestCode == PLACE_PICKER_REQUEST)
{
if(resultCode == RESULT_OK)
{
Place place = PlacePicker.getPlace(data,this);
Double latitude = place.getLatLng().latitude;
Double longitude = place.getLatLng().longitude;
String address = String.valueOf(latitude)+String.valueOf(longitude);
get_place.setText(address);
}
}
}
Current location coordinates not visible
.
After click on SELECT THIS BUTTON, below window opens with Select button is disabled
.
Please let me know, If there is any other best solution. Code reply will be much helpful or reference link.