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.
Solution: Enable Google Places API for Android from dev console.
I had the same issue (see comments in original post) and it turned out to be caused by a mismatch in the API key entry in the AndroidManifest.xml
file.
I'm using Xamarin.Android but the principle should be the same in Java - but your mileage may vary.
Basically my app was using the Maps API and in my manifest I had the API key specified as com.google.android.maps.v2.API_KEY
- and everything worked fine. When I implemented the Places Picker i needed to change the key name to com.google.android.geo.API_KEY
(I did NOT have to change the key itself!). I had done this for the debug configuration but NOT for the release configuration - which still used the Maps key name. Hence building a releasable package was resulting in a manifest which would satisfy the Maps API but not Places.
Changing the release configuration has resolved my issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With