Hi All,

i am using google Geocode service  via an HTTP request using java
below is my code
i am using for this

String GoogleMapAPIlocation="http://maps.google.com/maps/geo?q=";;
        if(bCCStore.getStreet2()!=null)
            GoogleMapAPIlocation=GoogleMapAPIlocation
+bCCStore.getStreet2()+",";
        if(bCCStore.getStreet()!=null)
            GoogleMapAPIlocation=GoogleMapAPIlocation
+bCCStore.getStreet()+",";
        if(bCCStore.getCity()!=null)
            GoogleMapAPIlocation=GoogleMapAPIlocation+bCCStore.getCity
()+",";
        if(bCCStore.getCountry()!=null)
            GoogleMapAPIlocation=GoogleMapAPIlocation
+bCCStore.getCountry()+",";
        if(bCCStore.getPostalCode()!=null)
            GoogleMapAPIlocation=GoogleMapAPIlocation
+bCCStore.getPostalCode();
        GoogleMapAPIlocation=GoogleMapAPIlocation
+"&output=csv&oe=utf8&sensor=false&key=";
        GoogleMapAPIlocation=GoogleMapAPIlocation+googleMapKey;
        GoogleMapAPIlocation=GoogleMapAPIlocation+"&gl=NL";
        System.out.println("**************************************
"+GoogleMapAPIlocation);
        int responseCode=0;
        try{
                /*
                 *  Calling Google MAP API over HTTP services.
                 *
                 */
                StringBuffer googleResponse = new StringBuffer();
                URL url = new URL(GoogleMapAPIlocation);
                HttpURLConnection huc = (HttpURLConnection)
url.openConnection();
                huc.setRequestMethod("POST");
                huc.setRequestProperty("Host", url.getHost());
                huc.setDoOutput(true);
                PrintWriter writer = new PrintWriter
(huc.getOutputStream());
                responseCode=huc.getResponseCode();
                System.out.println
("*****************************Response code is***************
"+responseCode);
                /*
                 *
                 * Response handling from Google MAP API
                 */
                if(responseCode==200){
                    BufferedReader br = new BufferedReader(new
InputStreamReader(huc.getInputStream()));
                    String line;
                    while ((line = br.readLine()) != null) {
                        googleResponse.append(line);

                    }

                   String geoCodeResponse=googleResponse.toString();
                   String[] splitGeoCodeResponse=geoCodeResponse.split
(",");
                   if(splitGeoCodeResponse.length>=4){
                        latitude= splitGeoCodeResponse[2];
                        longitude=splitGeoCodeResponse[3];

                      }
              }
      }
        catch (Exception e) {
            e.printStackTrace();
        }

the code is working fine and is able to get lat and long but for some
cases
i am getting HTTP response code as 400

and when i tried the request ed URL over webpage its providing me the
results butsame is not working using the above mentioned code.

can any one suggest me wheer i am doing wrong in code while the same
is working fine when i put the request string in web browser.

to test it furthur i even pause the request time as this code is
running inside a loop and theer are around 50 values means the looop
is executing 50 times

i put the pasue of around 1500MS but again results are same HTTP
response code 400

any help in this regard will be much helpfull
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to