public void buscar(View v) { mapa.clear(); if (mapa.getMyLocation() != null) { try { matches = geoCoder.getFromLocation( mapa.getMyLocation().getLatitude(), mapa.getMyLocation().getLongitude(), 1); } catch (IOException e) { e.printStackTrace(); } } else { try { matches = geoCoder.getFromLocation(gps.getLatitude(), gps.getLongitude(), 1); } catch (IOException e) { e.printStackTrace(); } } if (matches != null) { Search_Points bm = new Search_Points(matches, this); bm.execute(); } else Toast.makeText( this, "No se puede acceder a su ubicación, intente más tarde", Toast.LENGTH_SHORT) .show(); }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); // Activity sin parte superior requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_plantas_externas); gps = new MyLocationListener(this); geoCoder = new Geocoder(this); mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fragment)).getMap(); mapa.setMapType(GoogleMap.MAP_TYPE_NORMAL); mapa.setMyLocationEnabled(true); // mapa.setOnMapClickListener(this); mapa.getUiSettings().setMyLocationButtonEnabled(true); mapa.getUiSettings().setCompassEnabled(true); mapa.getUiSettings().setZoomControlsEnabled(true); mapa.setInfoWindowAdapter( new GoogleMap.InfoWindowAdapter() { @Override public View getInfoWindow(Marker marker) { return null; } @Override public View getInfoContents(Marker marker) { @SuppressLint("InflateParams") View v = getLayoutInflater().inflate(R.layout.map_marker_info_view, null); TextView Titulo = (TextView) v.findViewById(R.id.infoWindow_Titulo); TextView Description = (TextView) v.findViewById(R.id.infoWindow_descripcion); Titulo.setText(marker.getTitle()); Description.setText(marker.getSnippet()); return v; } }); mapa.setOnMapLoadedCallback(this); if (mapa != null) { if (mapa.getMyLocation() != null) { mapa.moveCamera( CameraUpdateFactory.newLatLngZoom( new LatLng(mapa.getMyLocation().getLatitude(), mapa.getMyLocation().getLongitude()), 15)); } else { try { mapa.moveCamera( CameraUpdateFactory.newLatLngZoom( new LatLng(gps.getLatitude(), gps.getLongitude()), 15)); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } } }