在這我嘗試擊中URL
bacground「response1」,但response1是打印空值,最新的問題。但是「HttpRes」也是打印在url中添加地址。請回復最新的問題。谷歌文本搜索URL在android中不工作
在我的代碼JSON不顯示在logcat時使用文本搜索網址我在上面的代碼中有什麼問題............................ ..................
10-06 09:50:56.391:I/System.out(19964):GeocoderTask latlnglat/lng:(19.0759837,72.8776559) 10-06 09:50:56.395:I/System.out(19964):AddressText === >>>孟買,馬哈拉施特拉邦,印度10-06 09:50:56.399:I/System.out(19964):HttpRes response ---- >>>>https://maps.googleapis.com/maps/api/place/textsearch/json?query=Mumbai,馬哈拉施特拉邦,印度& key = AIzaSyAoXVbnsD_AV8ejPliFjT3vIEtEXsv1lPc 10-06 09:50:56.399:I/System.out(19964):Addresstext response ---- >>>> null 10-06 09 :50:56.399:I/System.out(19964):Geocoder doInBackground response null
private class GeocoderTask extends AsyncTask<String, Void, String>{
String location,response1= null;
String addressText;
/**********************************************************/
public GeocoderTask(String location) {
this.location=location;
}
@Override
protected void onPreExecute() {
myServiceToHttp= new MyServiceToHttp();
List<Address> addresses = null;
Geocoder geocoder = new Geocoder(getBaseContext());
/**********************************************************/
try {
addresses = geocoder.getFromLocationName(location,1000);
} catch (IOException e) {
e.printStackTrace();
}
if(addresses==null || addresses.size()==0){
Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
googleMap.clear();
}
else {
if(addresses.size()>0)
for(int i=0;i<addresses.size();i++){
Address address = (Address) addresses.get(i);
// Creating an instance of GeoPoint, to display in Google Map
latLng = new LatLng(address.getLatitude(), address.getLongitude());
lat = address.getLatitude();
lng = address.getLongitude();
addressText = String.format("%s, %s",address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",address.getCountryName());
System.out.println(" GeocoderTask latlng" +latLng);
Toast.makeText(getApplicationContext(), "latlng" +String.valueOf(latLng), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Geolat == "+lat+ "Geolng == " +lng, Toast.LENGTH_SHORT).show();
System.out.println("AddressText===>>>" +addressText);
Toast.makeText(getApplicationContext(), "addressText"+addressText, Toast.LENGTH_SHORT).show();
marker = new MarkerOptions();
marker.position(latLng);
marker.title(addressText);
googleMap.addMarker(marker);
// Locate the first location
if(i==0){
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng) // Sets the center of the map to Mountain View
.zoom(10) // Sets the zoom
.bearing(40) // Sets the orientation of the camera to east
.tilt(5) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
}
super.onPreExecute();
}
@Override
protected String doInBackground(String... locationName) {
response1 = myServiceToHttp.makeServiceCall("https://maps.googleapis.com/maps/api/place/textsearch/json?query="+addressText+"&key=YOUR SERVER KEY",MyServiceToHttp.GET);
String HttpRes = "https://maps.googleapis.com/maps/api/place/textsearch/json?query="+addressText+"&key=YOUR SERVER KEY";
System.out.println("HttpRes response---->>>>" +HttpRes);
System.out.println("Addresstext response---->>>>" +response1);
if (response1!=null) {
try {
JSONObject jsonObject=new JSONObject(response1);
System.out.println("Json==>>>>"+jsonObject);
JSONArray array=jsonObject.getJSONArray("results");
System.out.println("JsonArray==>>>"+array);
}
catch (JSONException e)
{
e.printStackTrace();
}
}
else
{
System.out.println("Geocoder doInBackground response null");
}
return response1;
}
@Override
protected void onPostExecute(String addresses) {
Toast.makeText(getApplicationContext(), addresses, Toast.LENGTH_SHORT).show();
super.onPostExecute(addresses);
}
}
10-06 09:50:56.391:I/System.out(19964):GeocoderTask latlnglat/lng:(19.0759837,72.8776559)10-06 09:50:56.395:I/System.out(19964):AddressText === >>>孟買,馬哈拉施特拉邦,印度10-06 09:50:56.399:I/System .out(19964):HttpRes response ---- >>>> https://maps.googleapis.com/maps/api/place/textsearch/json?query=Mumbai,Maharashtra,India&key = AIzaSyAoXVbnsD_AV8ejPliFjT3vIEtEXsv1lPc 10-06 09: 50:56.399:I/System.out(19964):Addresstext response ---- >>>> null 10-06 09:50:56.399:I/System.out(19964):Geocoder doInBackground response 空值 – 2014-10-06 10:05:13