I’m using the following code to setup a mapview in android and display location marker which works well.
In addition I’m trying to use maps.googleapis.com with my api key to retrieve + display nearby XML nearby location data, either with Toast messages or in the debugger
I know I shouldn’t be running HTTPrequest on the main thread, but for debugging purposes I’m just trying to confirm that I’m actually retrieving the required JSON data
(it works in the browser with “https://maps.googleapis.com/maps/api/place/search/json?location=39.9165171,116.450872&radius=50&sensor=false&key=MYKEY“) for example
I’m getting an unable to resolve host error in Logcat
public class MainActivity extends MapActivity implements LocationListener {
MyLocationOverlay myLocationOverlay;
public MapView mapView;
MapController mc;
OverlayItem overlayitem;
List<Overlay> mapOverlays;
HelloItemizedOverlay itemizedoverlay;
GeoPoint myLocationGeoPoint;
String result = "nothing";
private MockGpsProvider mMockGpsProviderTask = null;
/* This method is called when use position will get changed */
public void onLocationChanged(Location location) {
final String TAG = getClass().getSimpleName();
String googleAPIKey = "xxxxxxxxx";
String searchRadius = "50";
String baseUrl = "https://maps.googleapis.com/maps/api/place/search/json?";
String lat = String.valueOf(location.getLatitude());
String lon = String.valueOf(location.getLongitude());
String url = baseUrl + "location=" + lat + "," + lon + "&" +
"radius=" + searchRadius + "&" + "sensor=false" +
"&" + "key=" + googleAPIKey;
Log.v(TAG,url);
Toast.makeText(this, url, Toast.LENGTH_LONG).show();
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
ResponseHandler<String> handler = new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
Log.v(TAG,result);
Toast.makeText(this, result, Toast.LENGTH_LONG).show();
}
never mind, figured it out by doing asyn task + json parsing