spinner_country.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Country country = (Country) parent.getSelectedItem(); Toast.makeText(context, "Country ID: "+country.getId()+", Country Name : "+country.getName(), Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<?> parent) { } });
@Override public void onLocationChanged(Location location) { if( mListener != null ) { mListener.onLocationChanged( location ); //Move the camera to the user's location and zoom in! mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 12.0f)); } }
private void setData() { ArrayList<Country> countryList = new ArrayList<>(); //Add countries countryList.add(new Country("1", "India")); countryList.add(new Country("2", "USA")); countryList.add(new Country("3", "China")); countryList.add(new Country("4", "UK")); //fill data in spinner ArrayAdapter<Country> adapter = new ArrayAdapter<Country>(context, android.R.layout.simple_spinner_dropdown_item, countryList); spinner_country.setAdapter(adapter); spinner_country.setSelection(adapter.getPosition(myItem));//Optional to set the selected item. }
private Record createRecord(final CityResponse city) { if (city == null) { return null; } final Map<String, Object> values = new HashMap<>(); values.put(CitySchema.CITY.getFieldName(), city.getCity().getName()); final Location location = city.getLocation(); values.put(CitySchema.ACCURACY.getFieldName(), location.getAccuracyRadius()); values.put(CitySchema.METRO_CODE.getFieldName(), location.getMetroCode()); values.put(CitySchema.TIMEZONE.getFieldName(), location.getTimeZone()); values.put(CitySchema.LATITUDE.getFieldName(), location.getLatitude()); values.put(CitySchema.LONGITUDE.getFieldName(), location.getLongitude()); values.put(CitySchema.CONTINENT.getFieldName(), city.getContinent().getName()); values.put(CitySchema.POSTALCODE.getFieldName(), city.getPostal().getCode()); values.put(CitySchema.COUNTRY.getFieldName(), createRecord(city.getCountry())); final Object[] subdivisions = new Object[city.getSubdivisions().size()]; int i = 0; for (final Subdivision subdivision : city.getSubdivisions()) { subdivisions[i++] = createRecord(subdivision); } values.put(CitySchema.SUBDIVISIONS.getFieldName(), subdivisions); return new MapRecord(CitySchema.GEO_SCHEMA, values); }
@VisibleForTesting Optional<GeoLocationInformation> extractGeoLocationInformation(Object fieldValue) { final InetAddress ipAddress; if (fieldValue instanceof InetAddress) { ipAddress = (InetAddress) fieldValue; } else if (fieldValue instanceof String) { ipAddress = getIpFromFieldValue((String) fieldValue); } else { ipAddress = null; } GeoLocationInformation geoLocationInformation = null; if (ipAddress != null) { try (Timer.Context ignored = resolveTime.time()) { final CityResponse response = databaseReader.city(ipAddress); final Location location = response.getLocation(); final Country country = response.getCountry(); final City city = response.getCity(); geoLocationInformation = GeoLocationInformation.create( location.getLatitude(), location.getLongitude(), country.getGeoNameId() != null ? country.getIsoCode() : "N/A", city.getGeoNameId() != null ? city.getName() : "N/A" // calling to .getName() may throw a NPE ); } catch (Exception e) { LOG.debug("Could not get location from IP {}", ipAddress.getHostAddress(), e); } } return Optional.ofNullable(geoLocationInformation); }
@Override public void onLocationChanged(Location location) { GeomagneticField field = new GeomagneticField( (float)location.getLatitude(), (float)location.getLongitude(), (float)location.getAltitude(), System.currentTimeMillis() ); // getDeclination returns degrees mDeclination = field.getDeclination(); }
private Record createRecord(final Subdivision subdivision) { if (subdivision == null) { return null; } final Map<String, Object> values = new HashMap<>(2); values.put(CitySchema.SUBDIVISION_NAME.getFieldName(), subdivision.getName()); values.put(CitySchema.SUBDIVISION_ISO.getFieldName(), subdivision.getIsoCode()); return new MapRecord(CitySchema.SUBDIVISION_SCHEMA, values); }
@Override public Object findInjectableValue(final Object valueId, final DeserializationContext ctxt, final BeanProperty forProperty, final Object beanInstance) throws JsonMappingException { if ("ip_address".equals(valueId)) { return ip; } else if ("traits".equals(valueId)) { return new Traits(ip); } else if ("locales".equals(valueId)) { return locales; } return null; } }
public void onLocationChanged(Location location) { currentLatitude = location.getLatitude(); currentLongitude = location.getLongitude();
public class Context { private final static Context instance = new Context(); public static Context getInstance() { return instance; } private Country country = new Country(); public Country currentCountry() { return country; } }
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double longitude = location.getLongitude(); double latitude = location.getLatitude();
@Override public void onLocationChanged(Location location) { if( mListener != null ) { mListener.onLocationChanged( location ); LatLngBounds bounds = this.mMap.getProjection().getVisibleRegion().latLngBounds; if(!bounds.contains(new LatLng(location.getLatitude(), location.getLongitude()))) { //Move the camera to the user's location if they are off-screen! mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()))); } } }
private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Override public void onMyLocationChange(Location arg0) { // TODO Auto-generated method stub mMap.addMarker(new MarkerOptions().position(new LatLng(arg0.getLatitude(), arg0.getLongitude())).title("It's Me!")); } }); } } }
private GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() { @Override public void onMyLocationChange(Location location) { LatLng loc = new LatLng(location.getLatitude(), location.getLongitude()); mMarker = mMap.addMarker(new MarkerOptions().position(loc)); if(mMap != null){ mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f)); } } };
@Override public void onLocationChanged(Location location) { if(now != null){ now.remove(); } TextView tvLocation = (TextView) findViewById(R.id.tv_location); // Getting latitude of the current location double latitude = location.getLatitude(); // Getting longitude of the current location double longitude = location.getLongitude(); // Creating a LatLng object for the current location LatLng latLng = new LatLng(latitude, longitude); now = googleMap.addMarker(new MarkerOptions().position(latLng))); // Showing the current location in Google Map googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); // Zoom in the Google Map googleMap.animateCamera(CameraUpdateFactory.zoomTo(15)); }
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(40) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); }
public void onLocationChanged(Location location) { double lat2 = location.getLatitude(); double lng2 = location.getLongitude();
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = service.getBestProvider(criteria, false); Location location = service.getLastKnownLocation(provider); LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());
@Override public void onClick(final View v) { Location location = this.mGoogleMap.getMyLocation(); if (location != null) { LatLng target = new LatLng(location.getLatitude(), location.getLongitude()); CameraPosition position = this.mGoogleMap.getCameraPosition(); Builder builder = new CameraPosition.Builder(); builder.zoom(15); builder.target(target); this.mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build())); } }
private void _getLocation() { // Get the location manager LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(bestProvider); try { lat = location.getLatitude(); lon = location.getLongitude(); } catch (NullPointerException e) { lat = -1.0; lon = -1.0; } }