Question

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"><Response>
  <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?

Was it helpful?

Solution

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&sensor=false&region=$region");
       $json = json_decode($json);

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

OTHER TIPS

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&q=90210

<AdministrativeArea>
    <AdministrativeAreaName>CA</AdministrativeAreaName>
    <SubAdministrativeArea>
        <SubAdministrativeAreaName>Los Angeles</SubAdministrativeAreaName>
        <Locality>
            <LocalityName>Beverly Hills</LocalityName>
            <PostalCode>
                <PostalCodeNumber>90210</PostalCodeNumber>
            </PostalCode>
        </Locality>
    </SubAdministrativeArea>
</AdministrativeArea>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top