Thanks Andrew,

I have tried to integrate LocalSearch with google map. Now I'm able to
get latitude and longititude for the >BT Auditorium, 81 Newgate
Street, London, EC1A 7AJ .

But when this way getting following message
---We are sorry but we don't have maps at this zoom level for this
region Try Zooming out for a broader look.

Currently I'm looking for above fix...



I'm also have some question about how i will use these two api in best
way

What is the difference in finding location using google map api and
local search api? each impact on performance ?
Should I search location in google map api if not found in it then
search in local search api? or
Should go direct to local search api for location (lat,long..).





Following is my code to search location by using Google ajax Local
Search api or Google Map api :-

 private void usingGoogleSearchApi(HttpServletResponse response,
String location,
            String googleMapApiKey) throws IOException, JSONException
    {

        float latitude;
        float longitude;

        // v stands for version (1.0,2.0, for beta 2.x)
        final String BASE_GOOGLE_SEARCH_URL = "http://
ajax.googleapis.com/ajax/services/search/local?v=1.0&";

        final String ENCODING = "UTF-8";

        String GOOGLE_SEARCH_QUERY_STRING = BASE_GOOGLE_SEARCH_URL +
"q=" + URLEncoder.encode(location, ENCODING);

        URL url = new URL(GOOGLE_SEARCH_QUERY_STRING);

        URLConnection connection = url.openConnection();
        //connection.addRequestProperty("Referer", "http://
www.mysite.com/index.html");

        String line;
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }

        JSONObject json = new JSONObject(builder.toString());

        System.out.println("JSON object = " + json);

        int statusCode = (Integer) json.get("responseStatus");

        System.out.println("Status code = " + statusCode);

        if (statusCode == 200) {

            JSONObject responseData = (JSONObject) json.get
("responseData");

            JSONObject viewport = (JSONObject) responseData.get
("viewport");

            JSONObject center = (JSONObject) viewport.get("center");

            JSONObject span = (JSONObject) viewport.get("span");

            JSONObject ne = (JSONObject) viewport.get("ne");

            JSONObject sw = (JSONObject) viewport.get("sw");

            System.out.println(center.get("lat"));
            System.out.println(center.get("lng"));

            response.setHeader("Cache-Control", "no-cache");
            response.getWriter().println(center);

        }

    } // end of method

 
--------------------------------------------------------------------------------------------------------------------------------------------------------
  private void usingGoogleMapApi(HttpServletResponse response, String
location, String googleMapApiKey)
            throws IOException, JSONException
    {

        float latitude;
        float longitude;

        final String BASE_GEOCODER_URL = "http://maps.google.com/maps/
geo?";
        final String ENCODING = "UTF-8";
        final String GOOGLE_MAPS_KEY = googleMapApiKey;
        final String OUTPUT_FORMAT = "csv";

        // goecoder complete url for getting latitude and longitude
        String GOOGLE_SEARCH_QUERY_STRING = BASE_GEOCODER_URL + "q=" +
URLEncoder.encode(location, ENCODING) + "&key="
                + GOOGLE_MAPS_KEY + "&output=" + OUTPUT_FORMAT;

        BufferedReader reader = new BufferedReader(new
InputStreamReader(new URL(GOOGLE_SEARCH_QUERY_STRING).openStream()));

        String line = null;
        int statusCode = -1;

        while ((line = reader.readLine()) != null) {

            // csv geocoding output ------------------------------
            // 200,4,37.320052,-121.877636 status
            // code,accuracy,latitude,longitude

            statusCode = Integer.parseInt(line.substring(0, 3));

            if (statusCode == 200) {
                int secondComma = line.indexOf(",", 5);
                int lastComma = line.lastIndexOf(",");

                latitude = Float.valueOf(line.substring(secondComma +
1, lastComma));
                longitude = Float.valueOf(line.substring(lastComma +
1));

                String jsonData = "{\"latitude\":\"" + latitude + "\",
\"longitude\":\"" + longitude + "\"}";

                // response.setContentType("text/xml");
response.setContentType("text/json");
                response.setHeader("Cache-Control", "no-cache");
                response.getWriter().println(jsonData);

                System.out.println("response :-" + line);
                System.out.println("Geocoding status code :-" +
statusCode);
                System.out.println("latitude :-" + latitude);
                System.out.println("longitude :-" + longitude);
            } // End of if
            // (statusCode
            // == 200)
            else {
                System.out.println("Geocoding status code :-" +
statusCode);
            }

        } // End of while
    }// end of method

On Jul 9, 12:14 pm, Andrew Leach <[email protected]>
wrote:
> On Jul 9, 6:24 am, sss <[email protected]> wrote:
>
> > This is address on which I'm getting 602 status code
> >             >BT Auditorium, 81 Newgate Street, London, EC1A 7AJ
>
> > The above address working absolutely fine(returning perfect location)
> > on thehttp://maps.google.com/
>
> > Any idea
>
> The API geocodes addresses, not what is at those addresses.
> maps.google uses other resources like LocalSearch as well as the
> geocoder. There is an API for LocalSearch; otherwise you will need to
> use just the address.
>
> Andrew
--~--~---------~--~----~------------~-------~--~----~
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