private void setZoomLevel() { Object[] keys = map.keySet().toArray(); OverlayItem item; if (keys.length > 1) { int minLatitude = Integer.MAX_VALUE; int maxLatitude = Integer.MIN_VALUE; int minLongitude = Integer.MAX_VALUE; int maxLongitude = Integer.MIN_VALUE; for (Object key : keys) { item = map.get((String) key); GeoPoint p = item.getPoint(); int lati = p.getLatitudeE6(); int lon = p.getLongitudeE6(); maxLatitude = Math.max(lati, maxLatitude); minLatitude = Math.min(lati, minLatitude); maxLongitude = Math.max(lon, maxLongitude); minLongitude = Math.min(lon, minLongitude); } mapController.zoomToSpan( Math.abs(maxLatitude - minLatitude), Math.abs(maxLongitude - minLongitude)); mapController.animateTo( new GeoPoint((maxLatitude + minLatitude) / 2, (maxLongitude + minLongitude) / 2)); } else { String key = (String) keys[0]; item = map.get(key); mapController.animateTo(item.getPoint()); while (mapController.zoomIn()) {} mapController.zoomOut(); } }
private void updateISSLocation() { if (CheckForUpdate()) { posOverlay.setLocation(currentlocation); mControl.animateTo(GetISSPos()); if (!dataSent) { if (FirstLock && !SecondLock) { posOverlay.setLock(1); dataSent = true; } if (SecondLock) { posOverlay.setLock(2); dataSent = true; } } } else if (pastlocation.getLatitude() != 0.0) { double latdist = jsonlocation.getLatitude() - pastlocation.getLatitude(); double longdist = jsonlocation.getLongitude() - pastlocation.getLongitude(); if (longdist < -300) { longdist = 180 + longdist; } double changelat = (latdist / 60) * TimeSinceLastUpdate; double changelong = (longdist / 60) * TimeSinceLastUpdate; currentlocation.setLatitude(jsonlocation.getLatitude() + changelat); currentlocation.setLongitude(jsonlocation.getLongitude() + changelong); posOverlay.setLocation(currentlocation); mControl.animateTo(GetISSPos()); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maptab); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); layout1 = (LinearLayout) findViewById(R.id.maptab1); // layout2 = (LinearLayout)findViewById(R.id.maptab2); BroadcastReceiver myReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "브로드캐스팅", 1000).show(); // layout1.setVisibility(View.GONE); // layout2.setVisibility(View.VISIBLE); } }; IntentFilter filter = new IntentFilter("bbb"); registerReceiver(myReceiver, filter); final MapController mc = mapView.getController(); GeoPoint point = new GeoPoint(37298025, 126972817); mc.animateTo(point); mc.setZoom(16); putBoardMarker(); }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.tabs); // Adding the zoom option mapView = (MapView) findViewById(R.id.MapView); LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom); View zoomView = mapView; zoomLayout.addView( zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"32.2217429", " -110.926479"}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(10); mapView.invalidate(); mapView.setSatellite(false); mapView.setStreetView(false); // bTakePicture = (Button)findViewById(R.id.bTakePicture); // bTakePicture.setOnClickListener(this); }
public void onLocationChanged(Location location) { int lat = (int) (location.getLatitude() * 1E6); int lng = (int) (location.getLongitude() * 1E6); GeoPoint point = new GeoPoint(lat, lng); createMarker(); mapController.animateTo(point); }
/** Called when a menu item is selected. */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case LOCATION_MOCKUP_SWITCH_ID: if (locationSource.getMode() == LocationSource.REAL_MODE) { // From REAL mode to MOCK mode: locationSource.setMode(LocationSource.MOCK_MODE); item.setTitle(R.string.map_menu_realGPS); } else { // From MOCK mode to REAL mode: locationSource.setMode(LocationSource.REAL_MODE); item.setTitle(R.string.map_menu_mockGPS); } break; case START_AR_VIEW_ID: startARViewBasic(); break; case CENTER_MAP_ON_CURRENT_LOCATION_ID: Location lastLoc = locationListener.getLastLocation(); if (lastLoc != null) myMapCtrl.animateTo(location2GP(locationListener.getLastLocation())); break; } return super.onOptionsItemSelected(item); }
protected void centerMap() { if (locationHelper.getLastLocation() != null) { GeoPoint geoPoint = geoPoint(locationHelper.getLastLocation()); MapController controller = mapView.getController(); controller.animateTo(geoPoint); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Displaying Zooming controls MapView mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); MapController mc = mapView.getController(); double lat = Double.parseDouble("10.35410"); // latitude double lon = Double.parseDouble("123.91145"); // longitude GeoPoint geoPoint = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)); mc.animateTo(geoPoint); mc.setZoom(15); mapView.invalidate(); List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.marker); AddItemizedOverlay itemizedOverlay = new AddItemizedOverlay(drawable, this); OverlayItem overlayitem = new OverlayItem(geoPoint, "Hello", "Talamban Campus"); itemizedOverlay.addOverlay(overlayitem); mapOverlays.add(itemizedOverlay); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.qtplace); // Set spinner content spnService = (Spinner) findViewById(R.id.spnPlace); ArrayAdapter<String> spnAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spnArr); spnAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spnService.setAdapter(spnAdapter); // Set mapview content mapView = (MapView) findViewById(R.id.map_view); mapController = mapView.getController(); mapView.setBuiltInZoomControls(true); // Get prefrences mapController.animateTo(testpoint); mapController.setZoom(14); // Set current location LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener ll = new myLocationListenner(); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); // Get distance txtDistance = (EditText) findViewById(R.id.txtDistance); // Set pointer in map mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.google_map_marker); itemizeOverlay = new CustomItemizeOverlay(drawable, this); }
public void navigaleToMapItem(int itemType, String itemIndex) { mapItem item = findItem(itemType, itemIndex); if (item != null) { mc.animateTo(item.gp); mc.setZoom(mZoomMax); } else { navigateToPoint(parent.naviPoint); } }
protected void onResume() { super.onResume(); Log.d(TAG, Boolean.toString(animateToTaskPosition)); registerReceiver(receiver, filter); if (animateToTaskPosition) { Task task = global_app.getDataStorage().getTaskById(taskId); GeoPoint tmp = new GeoPoint((int) (task.getLatitude() * 1E6), (int) (task.getLongitude() * 1E6)); mapController.animateTo(tmp); } else { lastLocation = global_app.getLastLocation(); int lat = (int) (lastLocation.getLatitude() * 1E6); int lng = (int) (lastLocation.getLongitude() * 1E6); geoPoint = new GeoPoint(lat, lng); mapController.animateTo(geoPoint); } paintCurrentPostion(); paintTasks(); }
public boolean onKeyDown(int keyCode, KeyEvent e) { if (keyCode == KeyEvent.KEYCODE_S) { mapView.setSatellite(!mapView.isSatellite()); return true; } else if (keyCode == KeyEvent.KEYCODE_T) { mapView.setTraffic(!mapView.isTraffic()); mapControl.animateTo(gp); // To ensure change displays immediately } return (super.onKeyDown(keyCode, e)); }
private void showPosition() { final GeoPoint myLocation = _myLocationOverlay.getMyLocation(); if (myLocation != null) { updateLocation(myLocation); _mc.animateTo(myLocation); } else { showNoLocationDialog(); } }
void updateLocation(final double lat, final double lon) { _lastPosition = Position.valueOf(lat, lon); Log.d(TAG, "Starting updateLocation " + lat + ", " + lon); Log.d(TAG, "My Location: " + _myLocationOverlay.getMyLocation()); _mc.animateTo(new GeoPoint((int) Math.round(lat * 1E6), (int) Math.round(lon * 1E6))); _mc.setZoom(DEFAULT_ZOOM_VALUE); getAndDisplayResultsFor(lat, lon); }
/* (non-Javadoc) * @see com.google.android.maps.ItemizedOverlay#onTap(int) */ @Override protected final boolean onTap(int index) { currentFocussedIndex = index; currentFocussedItem = createItem(index); createAndDisplayBalloonOverlay(); mc.animateTo(currentFocussedItem.getPoint()); return true; }
public void drawCenterMarker() { if (lat != null && lon != null) { ShopOverlay shopOverlay = new ShopOverlay(drawable); int dlat = (int) (Double.parseDouble(lat) * 1E6); int dlon = (int) (Double.parseDouble(lon) * 1E6); GeoPoint p = new GeoPoint(dlat, dlon); OverlayItem overlayItem = new OverlayItem(p, "", ""); shopOverlay.addOverlay(overlayItem); list.add(shopOverlay); mc.animateTo(p); } }
public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.item1: mControl.animateTo(GetISSPos()); return true; case R.id.item2: startActivity(new Intent(main.this, ISSWebView.class)); default: return super.onOptionsItemSelected(item); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapV = (MapView) findViewById(R.id.mapView); mapV.displayZoomControls(true); mapV.setBuiltInZoomControls(true); mapV.setSaveEnabled(true); initlocation.setLatitude(0.1); initlocation.setLongitude(0.1); GeoP = new GeoPoint( (int) (initlocation.getLatitude() * 1E6), (int) (initlocation.getLongitude() * 1E6)); posOverlay = new MapOverlay(); List<Overlay> overlays = mapV.getOverlays(); overlays.add(posOverlay); mControl = mapV.getController(); mControl.animateTo(GeoP); mControl.setZoom(5); Bitmap iss = BitmapFactory.decodeResource(getResources(), R.drawable.iss); Bitmap logo = BitmapFactory.decodeResource(getResources(), R.drawable.logo); Bitmap logotext = BitmapFactory.decodeResource(getResources(), R.drawable.logotext); Bitmap tracker = BitmapFactory.decodeResource(getResources(), R.drawable.isstracker); posOverlay.SetImages(iss, logo, logotext, tracker); posOverlay.setLocation(initlocation); if (CheckNetwork(getApplicationContext())) { startUpdateTimer(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage( "No data connection found, please check you have a mobile data connection or wifi enabled."); builder.setNegativeButton( "Quit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); finish(); } }); AlertDialog alert = builder.create(); alert.show(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); map = (MapView) findViewById(R.id.mvMain); map.setBuiltInZoomControls(true); Touchy t = new Touchy(); // Overlay para detectar toques en lapantalla oveList = map.getOverlays(); // obtiene todos los overlays que se dibujan en el mapa oveList.add(t); // agrega nuestro overlay de ultimo en la lista compass = new MyLocationOverlay( MainActivity.this, map); // se crea un nuevo Overlay de la localizacion actual oveList.add(compass); // se agrega el overlay de la localizacion controller = map.getController(); // se obtinenen los controles del mapa GeoPoint point = new GeoPoint(51643234, 7848593); // se crea un nuevo Geopoint controller.animateTo(point); // se indica a los controles que nos lleven al punto indicado controller.setZoom(6); // se hace un zoon de nivel 6 d = getResources() .getDrawable( R.drawable.ic_launcher); // se crea un objeto dibujable por medio de un recurso // placing pintpoint at location lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // manager para la localizacion GPS Criteria crit = new Criteria(); // un objeto criterio que maneja el mejor criterio de selleccion del // provider towers = lm.getBestProvider(crit, false); // se obtiene un proveedor de localizacion Location location = lm.getLastKnownLocation(towers); // se obtine la localizacion del provedor seleccionado // si hay una localizacion if (location != null) { lat = (int) location.getLatitude(); // se obtiene la lat y long lon = (int) location.getLongitude(); GeoPoint ourLocation = new GeoPoint(lat, lon); // se crea un nuevo punto // se crea un overlay para mostrar un dibujo en el punto indicado por la lat y lon OverlayItem overlayItem = new OverlayItem(ourLocation, "what's up", "2nd string"); CustonPinpoint custom = new CustonPinpoint( d, MainActivity.this); // se crea un punto personal con el objeto dibujable custom.insertPinpoint(overlayItem); // se le dan los datos de la posicion en el mapa oveList.add(custom); // se agrega el punto en la lista de overlays } else { // cuando todo se va al carajo Toast.makeText(MainActivity.this, "no se puede encontrar un provider", Toast.LENGTH_LONG) .show(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarContentView(R.layout.mapslist); initActionBar(); Bundle bundle = getIntent().getExtras(); session = bundle.getString("session"); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); controlMap = mapView.getController(); // Server Connection and convert response to string sc = new ServerConnection(this); String params = getResources().getString(R.string.llistatXarxes) + "?session=" + session; String result = sc.getDataConnection(params); // Recogemos los puntos // parse json data try { OverlayItem itemNet; JSONArray jArray = new JSONArray(result); prepareDraw(); for (int i = 0; i < jArray.length(); i++) { JSONObject json_data = jArray.getJSONObject(i); itemNet = new OverlayItem( new GeoPoint( (int) (json_data.getDouble("Lat") * 1E6), (int) (json_data.getDouble("Lon") * 1E6)), json_data.getString("Nom"), null); int idXarxa = json_data.getInt("IdXarxa"); itemizedOverlay.addOverlay(idXarxa, itemNet); } mapView.getOverlays().clear(); mapView.getOverlays().add(itemizedOverlay); // Recogemos el centro de los puntos y lo centramos GeoPoint point = itemizedOverlay.getCenter(); controlMap.animateTo(point); } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } controlMap.setZoom(8); }
private void inicializeMap() { mapView = (MapView) findViewById(R.id.map); mapView.setBuiltInZoomControls(true); mapController = mapView.getController(); mapController.setZoom(16); if (latitud != 0 && longitud != 0) { int lat = (int) (latitud * 1E6); int lon = (int) (longitud * 1E6); mapController.animateTo(new GeoPoint(lat, lon)); mapController.setCenter(new GeoPoint(lat, lon)); } centerMyPosition(); }
/** * Deze functie zet de meegegeven parameter, dit is een aders of plaats om naar een adres object * en zorgt ervoor dat de kaart op dit adres wordt gecentreerd en ingezoomd * * @param location * @return GeoPoint */ public GeoPoint createGeopoint(String location) { Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); List<Address> start = null; try { start = geoCoder.getFromLocationName(location, 1); } catch (IOException e) { e.printStackTrace(); } p = new GeoPoint( (int) (start.get(0).getLatitude() * 1E6), (int) (start.get(0).getLongitude() * 1E6)); mc.animateTo(p); mc.setZoom(13); return p; }
// M�todo chamado automaticamente pelo Android sempre que a localiza��o do GPS for alterada // Par�metro location contem a latitude e longitude atual. public void onLocationChanged(Location location) { Log.i(CATEGORIA, "latitude" + location.getLatitude() + " longitude" + location.getLongitude()); GeoPoint geoPoint = new Ponto(location); // Atualiza a imagem que representa o usuario no mapa imagem.setGeoPoint(geoPoint); imagem.setImagem(R.drawable.red_ball); mapa.getOverlays().add(imagem); // Anima o mapa at� a nova localiza��o controlador.animateTo(geoPoint); // invalida para desenhar novamente o mapa // mapa.invalidate(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_activity); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); double intentLatitude = getIntent().getDoubleExtra(Constants.EXTRA_POINT_LAT, 0.0); double intentLongitude = getIntent().getDoubleExtra(Constants.EXTRA_POINT_LON, 0.0); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mZoom = ZOOM_GLOBAL; if ((intentLatitude != 0.0) && (intentLongitude != 0.0)) { // the activity has been lauched with a commune's coordinate in extras mMapCenter = GeoUtils.convertLatLon(intentLatitude, intentLongitude); mZoom = ZOOM_FOCUSED; } else if (Constants.DEMO) { double lat = 47.07; double lon = 4.88; mMapCenter = GeoUtils.convertLatLon(lat, lon); } else { String provider = mLocationManager.getBestProvider(criteria, true); Location location = mLocationManager.getLastKnownLocation(provider); if (location != null) { mMapCenter = GeoUtils.convertGeoPoint(location); } else { double lat = 47.07; double lon = 4.88; mMapCenter = GeoUtils.convertLatLon(lat, lon); } } mMapView = (POIMapView) findViewById(R.id.mapview); mMapView.setBuiltInZoomControls(true); mMapController = mMapView.getController(); mMapController.setZoom(mZoom); mMapController.animateTo(mMapCenter); mMapView.setSatellite(MODE_SATELLITE); mMapView.setOnPanChangeListener(this); mHandler = new UIHandler(); initOverlay(); updateUI(); }
private void updateWithNewLocation(Location location) { TextView myLocationText; myLocationText = (TextView) findViewById(R.id.myLocationText); String latLongString = "No location found"; String addressString = "No address found"; if (location != null) { // Update the position overlay. positionOverlay.setLocation(location); Double geoLat = location.getLatitude() * 1E6; Double geoLng = location.getLongitude() * 1E6; GeoPoint point = new GeoPoint(geoLat.intValue(), geoLng.intValue()); mapController.animateTo(point); double lat = location.getLatitude(); double lng = location.getLongitude(); latLongString = "Lat:" + lat + "\nLong:" + lng; double latitude = location.getLatitude(); double longitude = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); if (!Geocoder.isPresent()) addressString = "No geocoder available"; else { try { List<Address> addresses = gc.getFromLocation(latitude, longitude, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); for (int i = 0; i < address.getMaxAddressLineIndex(); i++) sb.append(address.getAddressLine(i)).append("\n"); sb.append(address.getLocality()).append("\n"); sb.append(address.getPostalCode()).append("\n"); sb.append(address.getCountryName()); } addressString = sb.toString(); } catch (IOException e) { Log.d("WHEREAMI", "IO Exception", e); } } } myLocationText.setText("Your Current Position is:\n" + latLongString + "\n\n" + addressString); }
private void useLastKnownLocation(final LocationManager manager) { Location lastKnownLocation = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (lastKnownLocation == null) { lastKnownLocation = manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } if (lastKnownLocation != null) { updateLocation(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()); _mc.animateTo( new GeoPoint( (int) Math.round(lastKnownLocation.getLatitude() * 1E6), (int) Math.round(lastKnownLocation.getLongitude() * 1E6))); } else { updateLocation(_mapView.getMapCenter()); } }
@Override protected Boolean doInBackground(Void... params) { List<Overlay> mapOverlays = mMap.getOverlays(); mapOverlays.clear(); /* * Where i am */ Drawable meDrawable = getResources().getDrawable(R.drawable.me); CustomItemizedOverlay meItemizedOverlay = new CustomItemizedOverlay(meDrawable, mContext); GeoPoint mePoint = new GeoPoint( (int) (getLocation().getLatitude() * 1e6), (int) (getLocation().getLongitude() * 1e6)); OverlayItem meOverlayitem = new OverlayItem(mePoint, "Hello", "I'm here"); meItemizedOverlay.addOverlay(meOverlayitem); mapOverlays.add(meItemizedOverlay); records = GDGApi.getRecords(mContext, messageUtil); if (records != null && records.size() > 0) { for (int i = 0; i < records.size(); i++) { Record rec = records.get(i); Drawable drawable = null; if (rec.user.equals(mUserName)) { drawable = getResources().getDrawable(R.drawable.my_post); } else { drawable = getResources().getDrawable(R.drawable.other); } CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, mContext); itemizedOverlay.record = rec; GeoPoint point = new GeoPoint((int) (rec.locLatitude * 1e6), (int) (rec.locLongitude * 1e6)); OverlayItem overlayitem = new OverlayItem(point, rec.title, rec.body); itemizedOverlay.addOverlay(overlayitem); mapOverlays.add(itemizedOverlay); } } else { messageUtil.showToastMessage(getString(R.string.error_no_records)); } MapController mapController = mMap.getController(); mapController.animateTo(mePoint); mapController.setZoom(12); return false; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapa = (MapView) findViewById(R.id.mapaView); // Instancia do controlador do mapa controlador = mapa.getController(); // Instancia ums imagem (overlay) que representar� o usuario no mapa LocalUserOverlay imagem = new LocalUserOverlay(new PontoIzabel(), R.drawable.red_ball); mapa.getOverlays().add(imagem); // centraliza o mapa em uma determinada coordenada controlador.animateTo(new PontoIzabel()); // Centraliza o mapa na ultima localizacao conhecida LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); /* Location local = getLocationManager().getLastKnownLocation(LocationManager.GPS_PROVIDER); if(local != null){ //Se existe ultima localizacao converte para GeoPoint Ponto ponto = new Ponto(local);minTime //Instancia ums imagem (overlay) que representar� o usuario no mapa imagem = new LocalUserOverlay (ponto, R.drawable.red_ball); mapa.getOverlays().add(imagem); controlador.setCenter(ponto); }else{ getMensage("Aviso", "N�o foi possiver rastrear nova localiza��o"); } //GPS Listener getLocationManager().requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);*/ mapa.setStreetView(true); // configura pra mostrar o mapa no modo street mapa.setClickable(true); // define o zoom do mapa controlador.setZoom(19); mapa.setBuiltInZoomControls(true); }
private void locateToCurrentPosition() { MapView mapView = (MapView) findViewById(R.id.mapview); MapController mapController = mapView.getController(); final LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }; locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null) location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location == null) location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); if (location != null) { mapController.animateTo( new GeoPoint( (int) (location.getLatitude() * 1000000), (int) (location.getLongitude() * 1000000))); } }
// Set current location public void onLocationClick(View v) { if (curLocation == null) { Log.d("Veng", "GPS not found"); AlertDialog.Builder warn = new AlertDialog.Builder(QTPlaceActivity.this); warn.setTitle("GPS Error!") .setMessage("Your GPS is not enabled") .setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); warn.show(); } else { OverlayItem overlayItem = new OverlayItem(curLocation, "Hello", "You're here!"); itemizeOverlay.AddOverlay(overlayItem); mapOverlays.add(itemizeOverlay); mapController.animateTo(curLocation); } }