Created
April 21, 2015 02:42
-
-
Save rohandalvi/cbe7de2cd3748c6a5a75 to your computer and use it in GitHub Desktop.
MainActivity code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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