Goodnight. I wrote a PHP script that outputs the data in the format "0.0 0.0 name" (where 0.0 is the X and Y coordinates, respectively, and name is the name). These are coordinates of architectural objects to which I need to switch randomly the initial position of Google Maps. The script works fine: it displays everything correctly, if you go directly to the link of its location. However, my code in Android Studio does not accept this data. Tell me, please, what could be the problem:
public class GetMapPlace extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } public String getMapPlace() { String line = "0.0 0.0 none"; try { URL url = new URL(URL_GET_MAP); // подключаемся к интернету URLConnection connect = url.openConnection(); connect.setDoOutput(true); BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream())); // включаем буфер стандартного вывода, занося все в него (echo) StringBuilder builder = new StringBuilder(); if (reader.readLine() != null) { builder.append(line); // получаем строку } Log.d("DEBUG", "ОТВЕТ" + line); // эта строка не отображается в логах } catch (Exception e) { e.printStackTrace(); } return line; } } In addition to the absence of the DEBUG line in the logs, I tried to display the line value manually: it is always equal to "0.0 0.0 none".
Here's how I use this data in the future:
GetMapPlace activity = new GetMapPlace(); try { String line = activity.getMapPlace(); Log.d("DEBUG", "ERROR123" + " " + line); String[] words = line.split(" "); position1 = Float.parseFloat(words[0]); position2 = Float.parseFloat(words[1]); name = words[3]; } catch (Exception e) { e.printStackTrace(); } // For dropping a marker at a point on the Map LatLng sydney = new LatLng(position1, position2); googleMap.addMarker(new MarkerOptions().position(sydney).title(name).snippet("Marker Description")); // For zooming automatically to the location of the marker CameraPosition cameraPosition = new CameraPosition.Builder().target(sydney).zoom(12).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); I will be glad to any help! Happy New Year, gentlemen!