Skip to content

Instantly share code, notes, and snippets.

@rohandalvi
Created April 21, 2015 02:42
Show Gist options
  • Save rohandalvi/cbe7de2cd3748c6a5a75 to your computer and use it in GitHub Desktop.
Save rohandalvi/cbe7de2cd3748c6a5a75 to your computer and use it in GitHub Desktop.
MainActivity code
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import java.util.List;
import se.walkercrou.places.GooglePlaces;
import se.walkercrou.places.Place;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v("HI","HELLO");
new Thread(new Runnable() {
@Override
public void run() {
GooglePlaces client = new GooglePlaces("<MY API KEY HERE>");
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
List<Place> places = client.getNearbyPlaces(latitude,longitude,20);
for(Place i: places){
Log.v("Place ",i.getName());
}
}
}).run();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment