views:

224

answers:

2

Hello

i have used the following code to get the location of the particular place on map using the following piece of code

NSString * urlString = [[NSString alloc] initWithFormat:@"http://maps.google.com/maps/geo?key=%@&output=xml&q=%@",GoogleMapsAPIKey,[placeName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

result:

<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"&gt;&lt;Response&gt;
  <name>postdam</name>
  <Status>
    <code>200</code>
    <request>geocode</request>
  </Status>
  <Placemark id="p1">
    <address>Potsdam, Germany</address>
    <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Brandenburg</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Potsdam</SubAdministrativeAreaName><Locality><LocalityName>Potsdam</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="52.4513968" south="52.3424614" east="13.1866602" west="12.9305414" />
    </ExtendedData>
    <Point><coordinates>13.0586008,52.3969627,0</coordinates></Point>
  </Placemark>
</Response></kml>

but now i want to get the information agianst the zipcode how to do that using the maps.google.com ???

A: 

Since Google Maps is US centric, just putting in the zip code directly works (at least for the moment)

http://maps.google.com/maps/geo?output=xml&amp;q=90210

<AdministrativeArea>
    <AdministrativeAreaName>CA</AdministrativeAreaName>
    <SubAdministrativeArea>
        <SubAdministrativeAreaName>Los Angeles</SubAdministrativeAreaName>
        <Locality>
            <LocalityName>Beverly Hills</LocalityName>
            <PostalCode>
                <PostalCodeNumber>90210</PostalCodeNumber>
            </PostalCode>
        </Locality>
    </SubAdministrativeArea>
</AdministrativeArea>
nevan
if I give my query string in japanese characters, will it work?
Satyam svv
well not exactly, i am from Pakistan and my zipcode is 54600 i tried with the same url<kml>−<Response><name>54600</name>−<Status><code>200</code><request>geocode</request></Status>−<Placemark id="p1"><address>54600 Villers-lès-Nancy, France</address>−<AddressDetails Accuracy="5">−<Country><CountryNameCode>FR</CountryNameCode><CountryName>France</CountryName>−<AdministrativeArea><AdministrativeAreaName>Lorraine</AdministrativeAreaName>−<SubAdministrativeArea><SubAdministrativeAreaName>Meurthe-et-Moselle</SubAdministrativeAreaName>and so on ..... now what to do ?
yunas
This page has details about how to limit a search to a particular region: http://code.google.com/apis/maps/documentation/geocoding/index.html
nevan
yunas
+1  A: 

You no longer need to use the google maps API key to access this API.

Below is a PHP function I wrote yesterday to achieve exactly this in JSON

function getCoordinatesFromAddress($address, $lat, $long, $region="US") {
       $json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&amp;sensor=false&amp;region=$region");
       $json = json_decode($json);

       $lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
       $long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
}
adam