2016-05-05 13 views
2

Ich versuche, Koordinaten für die Adresse mit Yandex Geocode zu erhalten. Um zu beginnen, erstellte ich eine Abfrage direkt, wie es hier beschrieben wird https://tech.yandex.ru/maps/doc/geocoder/desc/concepts/input_params-docpage/Yandex API Geocode

Allerdings reagiert es, dass uri nicht korrekt ist. Wie ich herausgefunden habe, ist es weil uri russische Buchstaben enthält. Ich habe versucht, es mit URLEncoder zu beheben, aber nichts hat sich geändert. Ich werde für jede Art von Hilfe dankbar sein.

import com.sun.deploy.net.URLEncoder; 
import org.apache.commons.httpclient.HttpClient; 
import org.apache.commons.httpclient.HttpStatus; 
import org.apache.commons.httpclient.methods.GetMethod; 

public class Main { 
    public static void main(String[] args) { 
     String address = "Санкт-Петербург"; 
     try { 
      URLEncoder.encode(address, "UTF-8"); 
     } catch (Exception e) { 
      System.out.print("BAD"); 
     } 
     System.out.println(address); 
     HttpClient client = new HttpClient(); 
     String request = "https://geocode-maps.yandex.ru/1.x/?geocode=" + address; 
     GetMethod method = new GetMethod(request); 
     String Lat="",Long=""; 
     try { 
      client.executeMethod(method); 
      String s = method.getResponseBodyAsString(); 
      System.out.print(s); 
     } catch (Exception e) {} 
    } 
} 

Exception in thread "main" java.lang.IllegalArgumentException: Ungültige uri 'https://geocode-maps.yandex.ru/1.x/?geocode=Санкт-Петербург': Ungültige Abfrage

Antwort

1

Sie haben nicht wirklich die Zeichenfolge kodieren.

Bitte versuchen Sie es

address = URLEncoder.encode(... 
+0

ohhh :) Vielen Dank, es half –