I am working on an android application which requires user to select his/her location. I am using Google's PlacePikcer API to do so. It is working fine, but I want to show a particular area when I click on PlacePicker button. For example when I start the placepicker intent, it should show the map of a particular area or radius to make the search more specific. I searched a lot but couldn't find a way. Please help.
Asked
Active
Viewed 558 times
1 Answers
2
You can try the following approach.
LatLng bottomLeft = new LatLng(**bottom left latitude** , **bottom left longitude**);
LatLng topRight = new LatLng(**top right latitude** , **top right longitude**);
LatLngBounds bounds = new LatLngBounds(bottomLeft ,topRight);
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
intentBuilder.setLatLngBounds(bound);
// now use intentBuilder to build intent.
bottom left latitude and bottom left longitude mark the bottom left corner of the area you want to show and top right latitude and top right longitude mark the top right corner of the area.

Harjot Singh Oberai
- 282
- 2
- 14
-
Thanks.. it did help a lot. – Prateek Paliwal Oct 24 '16 at 08:47
-
Is it also possible to add only one `LatLng` as center of the screen and let the ``PlacePicker` build up the screen? Should be possible with the `Builder` but I can't get it work... – Cilenco Oct 24 '16 at 09:07
-
@Cilenco : build two LatLng as `new LatLng(center - 0.005, center - 0.005)` and `new LatLng(center + 0.005, center + 0.005)` and pass them into the LatLngBounds and use it in the Builder. Thus the PlacePicker will build the screen around the **center** the you specify. Increase **0.005** to some other value to get more area around **center**. Decrease it to reduce the area around **center**. – Harjot Singh Oberai Oct 24 '16 at 10:26
-
Thank you that worked for me after I changed the order of Longitude and Latitude in the `new LatLng(...)` statement. – Cilenco Nov 02 '16 at 12:13