Code Snippet Viewer

James Heffernan
Multimedia Developer/Designer

Location Finder

code snippet from Scio that finds location

Reverse Geo Code

Code snippet from Scio


	
locM = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

gps_isOn = locM.isProviderEnabled(LocationManager.GPS_PROVIDER); network_isOn = locM.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if(!gps_isOn && !network_isOn){
Context context = getApplicationContext();

nt duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, "nothing is enabled", duration); toast.show();

/*TODO maybe in the unlikely event that the user is in a dead-zone we could transport them to a new activity were they must input their location*/
}

if(gps_isOn)
locM.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListenerGps);

if(network_isOn)
locM.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListenerNet);
??
Line numbers



						

	
/*
* Now that we have the users location we need to reverse geoCode it to arrive at a String name instead * of double coordinates.
* */
Context context = getApplicationContext(); Geocoder geoC = new Geocoder(context);
if(geoC.isPresent()){ //TODO
}
Code Examples
Reverse Geo Code
List
list; try { list = geoC.getFromLocation(locLat, locLong,1); Address address = list.get(0); strB.append("Country: "+ address.getCountryName() + "\n"); // as I said we "could" try and obtain more exact location data. // strB.append("Name: "+ address.getLocality() + "\n"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }// double latitude,double longitude, 1= max results usrCountry = strB.toString(); /* * To test location is working we will set a "mock location" using the mocklocation method * */