Advertisement
nguyenvanquan7826

Untitled

Nov 7th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. private void search(String str) {
  2.         LatLng latLng = null;
  3.         if (str != null && !str.equals("")) {
  4.             String item[] = str.split(";");
  5.             if (item.length == 2) {
  6.                 try {
  7.                     double lat = Double.parseDouble(item[0]);
  8.                     double lng = Double.parseDouble(item[1]);
  9.                     latLng = new LatLng(lat, lng);
  10.  
  11.                 } catch (NumberFormatException ignored) {
  12.                 }
  13.             } else {
  14.                 Geocoder geocoder = new Geocoder(context);
  15.                 List<Address> adressList = null;
  16.                 try {
  17.                     adressList = geocoder.getFromLocationName(str, 1);
  18.                 } catch (IOException e) {
  19.                     e.printStackTrace();
  20.                 }
  21.                 if (adressList != null && adressList.size() > 0) {
  22.                     Address address = adressList.get(0);
  23.                     latLng = new LatLng(address.getLatitude(), address.getLongitude());
  24.                 }
  25.             }
  26.             if (latLng != null) {
  27.                 mMap.addMarker(new MarkerOptions().position(latLng));
  28.                 mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
  29.             } else {
  30.                 Var.showToast(context, context.getString(R.string.not_found_location) + " " + str);
  31.             }
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement