Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.93 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity implements OnMapReadyCallback,
  2. GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener,
  3. LocationListener, AdapterView.OnItemClickListener {
  4.  
  5. private GoogleMap mMap;
  6. GoogleApiClient mGoogleApiClient;
  7. Location mLastLocation;
  8. Marker mCurrLocationMarker,FindMarker;
  9. LocationRequest mLocationRequest;
  10. AutoCompleteTextView atvPlaces;
  11. DownloadTask placesDownloadTask;
  12. DownloadTask placeDetailsDownloadTask;
  13. ParserTask placesParserTask;
  14. ParserTask placeDetailsParserTask;
  15. LatLng latLng;
  16. final int PLACES = 0;
  17. final int PLACES_DETAILS = 1;
  18. ListView lv;
  19. ImageButton remove;
  20. private boolean exit = false;
  21.  
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.activity_main);
  26. // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  27. // setSupportActionBar(toolbar);
  28.  
  29. if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  30. checkLocationPermission();
  31. }
  32.  
  33. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  34. fab.setOnClickListener(new View.OnClickListener() {
  35.  
  36. @Override
  37. public void onClick(View view) {
  38. onLocationChanged(mLastLocation);
  39. }
  40. });
  41.  
  42. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
  43. .findFragmentById(R.id.map);
  44. mapFragment.getMapAsync(this);
  45.  
  46.  
  47. remove = (ImageButton)findViewById(R.id.place_autocomplete_clear_button);
  48.  
  49. // Getting a reference to the AutoCompleteTextView
  50. atvPlaces = (AutoCompleteTextView) findViewById(R.id.id_search_EditText);
  51. atvPlaces.setThreshold(1);
  52.  
  53. // Adding textchange listener
  54. atvPlaces.addTextChangedListener(new TextWatcher() {
  55.  
  56. @Override
  57. public void onTextChanged(CharSequence s, int start, int before, int count) {
  58. // Creating a DownloadTask to download Google Places matching "s"
  59. placesDownloadTask = new DownloadTask(PLACES);
  60.  
  61. // Getting url to the Google Places Autocomplete api
  62. String url = getAutoCompleteUrl(s.toString().trim());
  63.  
  64. // Start downloading Google Places
  65. // This causes to execute doInBackground() of DownloadTask class
  66.  
  67. placesDownloadTask.execute(url);
  68.  
  69.  
  70. if (!atvPlaces.getText().toString().equals("")){
  71. lv.setVisibility(View.VISIBLE);
  72. remove.setVisibility(View.VISIBLE);
  73. }else {
  74. lv.setVisibility(View.GONE);
  75. remove.setVisibility(View.GONE);
  76. }
  77.  
  78.  
  79. }
  80.  
  81. @Override
  82. public void beforeTextChanged(CharSequence s, int start, int count,
  83. int after) {
  84. // TODO Auto-generated method stub
  85. }
  86.  
  87. @Override
  88. public void afterTextChanged(Editable s) {
  89. // TODO Auto-generated method stub
  90. }
  91. });
  92.  
  93. // Setting an item click listener for the AutoCompleteTextView dropdown list
  94. /* atvPlaces.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  95. @Override
  96. public void onItemClick(AdapterView<?> arg0, View arg1, int index,
  97. long id) {
  98.  
  99. ListView lv = (ListView) arg0;
  100. SimpleAdapter adapter = (SimpleAdapter) arg0.getAdapter();
  101.  
  102. HashMap<String, String> hm = (HashMap<String, String>) adapter.getItem(index);
  103.  
  104. // Creating a DownloadTask to download Places details of the selected place
  105. placeDetailsDownloadTask = new DownloadTask(PLACES_DETAILS);
  106.  
  107. // Getting url to the Google Places details api
  108. String url = getPlaceDetailsUrl(hm.get("reference"));
  109.  
  110. // Start downloading Google Place Details
  111. // This causes to execute doInBackground() of DownloadTask class
  112. placeDetailsDownloadTask.execute(url);
  113.  
  114. InputMethodManager inputManager = (InputMethodManager)
  115. getSystemService(Context.INPUT_METHOD_SERVICE);
  116.  
  117. inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken (),
  118. InputMethodManager.HIDE_NOT_ALWAYS);
  119.  
  120.  
  121. }
  122. });*/
  123. lv=(ListView)findViewById(R.id.list);
  124.  
  125. lv.setOnItemClickListener(this);
  126.  
  127.  
  128. setListenerOnWidget();
  129. }
  130.  
  131. private void setListenerOnWidget() {
  132. View.OnClickListener listener = new View.OnClickListener() {
  133. @Override
  134. public void onClick(View view) {
  135. atvPlaces.setText("");
  136. }
  137. };
  138. remove.setOnClickListener(listener);
  139. }
  140.  
  141. @Override
  142. public void onBackPressed() {
  143. if(exit){
  144. finish();
  145. }else {
  146. Toast.makeText(this, "Tap Back again to Exit.",
  147. Toast.LENGTH_SHORT).show();
  148. exit = true;
  149. new Handler().postDelayed(new Runnable() {
  150. @Override
  151. public void run() {
  152. exit = false;
  153. }
  154. }, 3 * 1000);
  155.  
  156. }
  157. }
  158.  
  159.  
  160. @Override
  161. public void onItemClick (AdapterView < ? > adapterView, View view,int i, long l){
  162. //ListView lv = (ListView) adapterView;
  163. SimpleAdapter adapter = (SimpleAdapter) adapterView.getAdapter();
  164.  
  165. HashMap<String, String> hm = (HashMap<String, String>) adapter.getItem(i);
  166.  
  167. // Creating a DownloadTask to download Places details of the selected place
  168. placeDetailsDownloadTask = new DownloadTask(PLACES_DETAILS);
  169.  
  170. // Getting url to the Google Places details api
  171. String url = getPlaceDetailsUrl(hm.get("reference"));
  172.  
  173. // Start downloading Google Place Details
  174. // This causes to execute doInBackground() of DownloadTask class
  175. placeDetailsDownloadTask.execute(url);
  176.  
  177. InputMethodManager inputManager = (InputMethodManager)
  178. getSystemService(Context.INPUT_METHOD_SERVICE);
  179.  
  180. inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
  181. InputMethodManager.HIDE_NOT_ALWAYS);
  182.  
  183. String str = ((TextView) view.findViewById(R.id.place_name)).getText().toString();
  184. Toast.makeText(this,str, Toast.LENGTH_SHORT).show();
  185. //atvPlaces.setText(str.replace(' ',','));
  186. atvPlaces.setText(str);
  187.  
  188. lv.setVisibility(view.GONE);
  189.  
  190.  
  191. }
  192.  
  193.  
  194.  
  195. private String getPlaceDetailsUrl(String ref) {
  196. // Obtain browser key from https://code.google.com/apis/console
  197. String key = "key=****************************";
  198.  
  199. // reference of place
  200. String reference = "reference=" + ref;
  201.  
  202. // Sensor enabled
  203. String sensor = "sensor=false";
  204.  
  205. // Building the parameters to the web service
  206. String parameters = reference + "&" + sensor + "&" + key;
  207.  
  208. // Output format
  209. String output = "json";
  210.  
  211. // Building the url to the web service
  212. String url = "https://maps.googleapis.com/maps/api/place/details/" + output + "?" + parameters;
  213.  
  214. return url;
  215. }
  216.  
  217. private String getAutoCompleteUrl(String place) {
  218. // Obtain browser key from https://code.google.com/apis/console
  219. String key = "key=AIzaSyCQNRAkYhQ4CDwDV-0Oh-kNFdrUY1NwSI0";
  220.  
  221. // place to be be searched
  222. String input = "input=" + place;
  223.  
  224. // place type to be searched
  225. String types = "types=geocode";
  226.  
  227. // Sensor enabled
  228. String sensor = "sensor=false";
  229.  
  230. // Building the parameters to the web service
  231. String parameters = input + "&" + types + "&" + sensor + "&" + key;
  232.  
  233. // Output format
  234. String output = "json";
  235.  
  236. // Building the url to the web service
  237. String url = "https://maps.googleapis.com/maps/api/place/autocomplete/" + output + "?" + parameters;
  238.  
  239. return url;
  240. }
  241.  
  242. /**
  243. * A method to download json data from url
  244. */
  245. private String downloadUrl(String strUrl) throws IOException {
  246. String data = "";
  247. InputStream iStream = null;
  248. HttpURLConnection urlConnection = null;
  249. try {
  250. URL url = new URL(strUrl);
  251.  
  252. // Creating an http connection to communicate with url
  253. urlConnection = (HttpURLConnection) url.openConnection();
  254.  
  255. // Connecting to url
  256. urlConnection.connect();
  257.  
  258. // Reading data from url
  259. iStream = urlConnection.getInputStream();
  260.  
  261. BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
  262.  
  263. StringBuffer sb = new StringBuffer();
  264.  
  265. String line = "";
  266. while ((line = br.readLine()) != null) {
  267. sb.append(line);
  268. }
  269.  
  270. data = sb.toString();
  271.  
  272. br.close();
  273.  
  274. } catch (Exception e) {
  275. Log.d("Exception while downloading url", e.toString());
  276. } finally {
  277. iStream.close();
  278. urlConnection.disconnect();
  279. }
  280. return data;
  281. }
  282.  
  283. public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
  284.  
  285. public boolean checkLocationPermission() {
  286. if (ContextCompat.checkSelfPermission(this,
  287. Manifest.permission.ACCESS_FINE_LOCATION)
  288. != PackageManager.PERMISSION_GRANTED) {
  289.  
  290. if (ActivityCompat.shouldShowRequestPermissionRationale(this,
  291. Manifest.permission.ACCESS_FINE_LOCATION)) {
  292.  
  293. ActivityCompat.requestPermissions(this,
  294. new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
  295. MY_PERMISSIONS_REQUEST_LOCATION);
  296. } else {
  297. ActivityCompat.requestPermissions(this,
  298. new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
  299. MY_PERMISSIONS_REQUEST_LOCATION);
  300. }
  301. return false;
  302. } else {
  303. return true;
  304. }
  305.  
  306. }
  307.  
  308. @Override
  309. public boolean onCreateOptionsMenu(Menu menu) {
  310. // Inflate the menu; this adds items to the action bar if it is present.
  311. getMenuInflater().inflate(R.menu.menu_main, menu);
  312. return true;
  313. }
  314.  
  315. @Override
  316. public boolean onOptionsItemSelected(MenuItem item) {
  317. // Handle action bar item clicks here. The action bar will
  318. // automatically handle clicks on the Home/Up button, so long
  319. // as you specify a parent activity in AndroidManifest.xml.
  320. int id = item.getItemId();
  321.  
  322. //noinspection SimplifiableIfStatement
  323. if (id == R.id.action_settings) {
  324. return true;
  325. }
  326.  
  327. return super.onOptionsItemSelected(item);
  328. }
  329.  
  330. @Override
  331. public void onConnected(@Nullable Bundle bundle) {
  332. mLocationRequest = new LocationRequest();
  333. //mLocationRequest.setInterval(1000);
  334. //mLocationRequest.setFastestInterval(1000);
  335. mLocationRequest.setPriority (LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
  336.  
  337. if (ContextCompat.checkSelfPermission(this,
  338. Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
  339. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
  340. }
  341. }
  342.  
  343. @Override
  344. public void onConnectionSuspended(int i) {
  345.  
  346. }
  347.  
  348. @Override
  349. public void onLocationChanged(Location location) {
  350. mLastLocation = location;
  351. if(mCurrLocationMarker != null){
  352. mCurrLocationMarker.remove();
  353. }
  354.  
  355. LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
  356. MarkerOptions markerOption = new MarkerOptions();
  357. markerOption.position(latLng);
  358. markerOption.title("Current Position");
  359. markerOption.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
  360. mCurrLocationMarker = mMap.addMarker(markerOption);
  361. Toast.makeText(this,"Location changed",Toast.LENGTH_SHORT).show();
  362. CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(13).build();
  363. mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
  364.  
  365. if(mGoogleApiClient != null){
  366. LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,this);
  367. }
  368.  
  369. loadNearByPlaces(location.getLatitude(), location.getLongitude());
  370. }
  371.  
  372. @Override
  373. public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
  374.  
  375. }
  376.  
  377. @Override
  378. public void onMapReady(GoogleMap googleMap) {
  379.  
  380. mMap = googleMap;
  381.  
  382. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  383. if (ContextCompat.checkSelfPermission(this,
  384. android.Manifest.permission.ACCESS_FINE_LOCATION)
  385. == PackageManager.PERMISSION_GRANTED) {
  386. buildGoogleApiClient();
  387. mMap.setMyLocationEnabled(true);
  388.  
  389. }
  390. } else {
  391. buildGoogleApiClient();
  392. mMap.setMyLocationEnabled(true);
  393. }
  394.  
  395. }
  396.  
  397. protected synchronized void buildGoogleApiClient() {
  398. mGoogleApiClient = new GoogleApiClient.Builder(this)
  399. .addConnectionCallbacks(this)
  400. .addOnConnectionFailedListener(this)
  401. .addApi(LocationServices.API)
  402. .build();
  403. mGoogleApiClient.connect();
  404. }
  405.  
  406. @Override
  407. public void onRequestPermissionsResult(int requestCode,
  408. String permissions[], int[] grantResult) {
  409. switch (requestCode) {
  410. case MY_PERMISSIONS_REQUEST_LOCATION: {
  411.  
  412. if (grantResult.length > 0
  413. && grantResult[0] == PackageManager.PERMISSION_GRANTED) {
  414. if (ContextCompat.checkSelfPermission(this,
  415. Manifest.permission.ACCESS_FINE_LOCATION)
  416. == PackageManager.PERMISSION_GRANTED) {
  417. if (mGoogleApiClient == null) {
  418. buildGoogleApiClient();
  419. }
  420. mMap.setMyLocationEnabled(true);
  421. }
  422.  
  423. } else {
  424. Toast.makeText(this, "permisison denied", Toast.LENGTH_LONG).show();
  425. }
  426. return;
  427. }
  428.  
  429. }
  430. }
  431.  
  432. private void loadNearByPlaces(double latitude, double longitude) {
  433. //YOU Can change this type at your own will, e.g hospital, cafe, restaurant.... and see how it all works
  434. String type = "atm";
  435. StringBuilder googlePlacesUrl =
  436. new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
  437. googlePlacesUrl.append("location=").append(latitude).append(",").append(longitude);
  438. googlePlacesUrl.append("&radius=").append(PROXIMITY_RADIUS);
  439. googlePlacesUrl.append("&types=").append(type);
  440. googlePlacesUrl.append("&sensor=true");
  441. googlePlacesUrl.append("&key=" + GOOGLE_BROWSER_API_KEY);
  442.  
  443. JsonObjectRequest request = new JsonObjectRequest(googlePlacesUrl.toString(),
  444. new Response.Listener<JSONObject>() {
  445. @Override
  446. public void onResponse(JSONObject result) {
  447.  
  448. Log.i(TAG, "onResponse: Result= " + result.toString());
  449. parseLocationResult(result);
  450. }
  451. },
  452. new Response.ErrorListener() {
  453. @Override
  454. public void onErrorResponse(VolleyError error) {
  455. Log.e(TAG, "onErrorResponse: Error= " + error);
  456. Log.e(TAG, "onErrorResponse: Error= " + error.getMessage());
  457. }
  458. });
  459.  
  460. AppController.getInstance().addToRequestQueue(request);
  461. }
  462.  
  463. private void parseLocationResult(JSONObject result) {
  464.  
  465. String id, place_id, placeName = null, reference, icon, vicinity = null;
  466. double latitude, longitude;
  467.  
  468. try {
  469. JSONArray jsonArray = result.getJSONArray("results");
  470.  
  471. if (result.getString(STATUS).equalsIgnoreCase(OK)) {
  472.  
  473. //mMap.clear();
  474.  
  475. for (int i = 0; i < jsonArray.length(); i++) {
  476. JSONObject place = jsonArray.getJSONObject(i);
  477.  
  478. id = place.getString(ATM_ID);
  479. place_id = place.getString(PLACE_ID);
  480. if (!place.isNull(NAME)) {
  481. placeName = place.getString(NAME);
  482. }
  483. if (!place.isNull(VICINITY)) {
  484. vicinity = place.getString(VICINITY);
  485. }
  486. latitude = place.getJSONObject(GEOMETRY).getJSONObject(LOCATION)
  487. .getDouble(LATITUDE);
  488. longitude = place.getJSONObject(GEOMETRY).getJSONObject(LOCATION)
  489. .getDouble(LONGITUDE);
  490. reference = place.getString(REFERENCE);
  491. icon = place.getString(ICON);
  492.  
  493. MarkerOptions markerOptions = new MarkerOptions();
  494. LatLng latLng = new LatLng(latitude, longitude);
  495. markerOptions.position(latLng);
  496. markerOptions.title(placeName);
  497. markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
  498. markerOptions.snippet(vicinity);
  499. mMap.addMarker(markerOptions);
  500.  
  501. mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
  502.  
  503. @Override
  504. public View getInfoWindow(Marker arg0) {
  505.  
  506. return null;
  507. }
  508.  
  509. @Override
  510. public View getInfoContents(Marker marker) {
  511. View myContentsView = getLayoutInflater().inflate(R.layout.marker, null);
  512. TextView tvTitle = ((TextView)myContentsView.findViewById(R.id.title));
  513. tvTitle.setText(marker.getTitle());
  514. TextView tvSnippet = ((TextView)myContentsView.findViewById(R.id.snippet));
  515. tvSnippet.setText(marker.getSnippet());
  516. return myContentsView;
  517. }
  518. });
  519.  
  520. }
  521.  
  522. Toast.makeText(getBaseContext(), jsonArray.length() + " ATM_FOUND!",
  523. Toast.LENGTH_SHORT).show();
  524. } else if (result.getString(STATUS).equalsIgnoreCase(ZERO_RESULTS)) {
  525. Toast.makeText(getBaseContext(), "No ATM found in 5KM radius!!!",
  526. Toast.LENGTH_LONG).show();
  527. }
  528.  
  529. } catch (JSONException e) {
  530.  
  531. e.printStackTrace();
  532. Log.e(TAG, "parseLocationResult: Error=" + e.getMessage());
  533. }
  534. }
  535.  
  536. private class DownloadTask extends AsyncTask<String, Void, String> {
  537. private int downloadType = 0;
  538.  
  539. // Constructor
  540. public DownloadTask(int type) {
  541. this.downloadType = type;
  542. }
  543.  
  544. @Override
  545. protected String doInBackground(String... url) {
  546. // For storing data from web service
  547. String data = "";
  548.  
  549. try {
  550. // Fetching the data from web service
  551. data = downloadUrl(url[0]);
  552. } catch (Exception e) {
  553. Log.d("Background Task", e.toString());
  554. }
  555. return data;
  556. }
  557.  
  558. @Override
  559. protected void onPostExecute(String result) {
  560. super.onPostExecute(result);
  561.  
  562. switch (downloadType) {
  563. case PLACES:
  564. // Creating ParserTask for parsing Google Places
  565. placesParserTask = new ParserTask(PLACES);
  566.  
  567. // Start parsing google places json data
  568. // This causes to execute doInBackground() of ParserTask class
  569. placesParserTask.execute(result);
  570.  
  571. break;
  572.  
  573. case PLACES_DETAILS:
  574. // Creating ParserTask for parsing Google Places
  575. placeDetailsParserTask = new ParserTask(PLACES_DETAILS);
  576.  
  577. // Starting Parsing the JSON string
  578. // This causes to execute doInBackground() of ParserTask class
  579. placeDetailsParserTask.execute(result);
  580. }
  581. }
  582. }
  583.  
  584. /**
  585. * A class to parse the Google Places in JSON format
  586. */
  587. private class ParserTask extends AsyncTask<String, Integer, List<HashMap<String, String>>> {
  588.  
  589. int parserType = 0;
  590.  
  591. public ParserTask(int type) {
  592. this.parserType = type;
  593. }
  594.  
  595. @Override
  596. protected List<HashMap<String, String>> doInBackground(String... jsonData) {
  597.  
  598. JSONObject jObject;
  599. List<HashMap<String, String>> list = new ArrayList<>();
  600.  
  601. try {
  602. jObject = new JSONObject(jsonData[0]);
  603.  
  604. switch (parserType) {
  605. case PLACES:
  606. PlaceJSONParser placeJsonParser = new PlaceJSONParser();
  607. // Getting the parsed data as a List construct
  608. list = placeJsonParser.parse(jObject);
  609. break;
  610. case PLACES_DETAILS:
  611. PlaceDetailsJSONParser placeDetailsJsonParser = new PlaceDetailsJSONParser();
  612. // Getting the parsed data as a List construct
  613. list = placeDetailsJsonParser.parse(jObject);
  614. }
  615.  
  616. } catch (Exception e) {
  617. Log.d("Exception", e.toString());
  618. }
  619. return list;
  620. }
  621.  
  622. @Override
  623. protected void onPostExecute(List<HashMap<String, String>> result) {
  624.  
  625. switch (parserType) {
  626. case PLACES:
  627. String[] from = new String[]{"description"};
  628. int[] to = new int[]{R.id.place_name};
  629.  
  630. // Creating a SimpleAdapter for the AutoCompleteTextView
  631. //SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), result, android.R.layout.simple_list_item_1, from, to);
  632.  
  633. // Setting the adapter
  634. //atvPlaces.setAdapter(adapter);
  635.  
  636. ListAdapter adapter = new SimpleAdapter(MainActivity.this, result,R.layout.row,from,to);
  637. // Adding data into listview
  638. lv.setAdapter(adapter);
  639. break;
  640. case PLACES_DETAILS:
  641. String location = atvPlaces.getText().toString();
  642. if (location != null && !location.equals("")) {
  643. new GeocoderTask().execute(location);
  644.  
  645.  
  646. }
  647.  
  648. break;
  649. }
  650. }
  651. }
  652.  
  653. private class GeocoderTask extends AsyncTask<String, Void, List<Address>> {
  654.  
  655. @Override
  656. protected List<Address> doInBackground(String... locationName) {
  657. // TODO Auto-generated method stub
  658.  
  659. Geocoder geocoder = new Geocoder(getBaseContext());
  660. List<Address> addresses = null;
  661.  
  662. try {
  663. // Getting a maximum of 3 Address that matches the input text
  664. addresses = geocoder.getFromLocationName(locationName[0], 3);
  665. } catch (IOException e) {
  666. e.printStackTrace();
  667. }
  668. return addresses;
  669. }
  670.  
  671. protected void onPostExecute(List<Address> addresses) {
  672. if(addresses==null || addresses.size()==0){
  673. Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
  674. }
  675. for(int i=0;i<addresses.size();i++){
  676. Address address = (Address)addresses.get(i);
  677. latLng = new LatLng(address.getLatitude(), address.getLongitude());
  678. String addressText = String.format("%s, %s",
  679. address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
  680. address.getCountryName());
  681. MarkerOptions markerOptions = new MarkerOptions();
  682. markerOptions.position(latLng);
  683. markerOptions.title("Find Location");
  684. markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
  685. FindMarker = mMap.addMarker(markerOptions);
  686.  
  687. CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(13).build();
  688. mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
  689.  
  690. loadNearByPlaces(address.getLatitude(), address.getLongitude());
  691.  
  692.  
  693. }
  694.  
  695. }
  696.  
  697. }
  698.  
  699. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement