Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3677998
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:17:20+00:00 2026-05-19T03:17:20+00:00

Here is my current code on how I’m getting different components. function getGeocodeFull($address) {

  • 0

Here is my current code on how I’m getting different components.

function getGeocodeFull($address)
{
    if (empty($address)) return false;

    $_geocode = false; 

    if (($_geocode = $this->getCache($address)) === false) // check if address is has a cache
    {
        if (($results = $this->geoGetCoordsFull($address)) !== false) 
        {
            // sloooooooooopppy.. yes these can all be combined, i know.
            if (!isset($results->results[0]->geometry->location->lat))  return false;
            if (!isset($results->results[0]->geometry->location->lat))  return false;
            if (!isset($results->results[0]->formatted_address))        return false;
            if (!isset($results->results[0]->address_components))       return false;

            $_geocode['lat']     = $results->results[0]->geometry->location->lat;
            $_geocode['lon']     = $results->results[0]->geometry->location->lng;
            $_geocode['address'] = $results->results[0]->formatted_address;

            foreach ($results->results[0]->address_components as $component)
            {
                if (isset($component->types))
                {
                    foreach ($component->types as $type)
                    {
                        switch ($type)
                        {
                            case 'route':
                                $_geocode['street'] = $component->long_name;
                                break;
                            case 'locality':
                                $_geocode['city'] = $component->long_name;
                                break;
                            case 'administrative_area_level_2':
                                $_geocode['county'] = $component->long_name;
                                break;
                            case 'administrative_area_level_3':
                                $_geocode['area'] = $component->long_name;
                                break;
                            case 'postal_code':
                                $_geocode['zip'] = $component->short_name;
                                break;
                        }     
                    }
                }    
            }

            $this->putCacheFull($address, $_geocode['lat'], $_geocode['lon'], $_geocode['address'], $_geocode['street'], $_geocode['city'], $_geocode['county'], $_geocode['area'], $_geocode['zip']);
        }
    }

    return $_geocode;
}

geoGetCoordsFull() simply uses file_get_contents on the google map api geocode page, then decodes the results then returns them.

I’m not too big of a fan of what that looks like. It seems like it can be very inconsistent. Are there any other BETTER solutions to getting all the data from google or any other service?

I’d prefer another service that doesn’t limit requests (or is it illegal to use multiple geocode services such as bing/yahoo/etc) ?? (sorry for throwing in another question)

Anyway, much help would be very appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:17:20+00:00Added an answer on May 19, 2026 at 3:17 am

    I went about it another way, I’ve removed a bit of code for brevity, but basically I had a table with about 16’000 locations (all locations in Australia) and looped through them all to find them on Google Maps, retrieve the lat long info and store back in the table so it never had to be looked up again

    $row contains an array of details for the location I’m looking up, like the address, postcode, suburb and state

    You’ll also need to get an API key from Google Maps for this code, as it uses v2. I don’t think you need one anymore for v3

    define("MAPS_HOST", "maps.google.com");
    define("KEY", "YOU_KEY_HERE");
    
    // Initialize delay in geocode speed
    $delay = 0;
    $lat = '';
    $lng = '';
    $base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY;
    
      $geocode_pending = true;
      while ($geocode_pending) {
    
        flush();
    
        $address = $row['suburb'] . ' ' . $row['postcode'] . ', ' . $row['state'] . ' Australia';
        $request_url = $base_url . "&q=" . urlencode($address);
        $xml = simplexml_load_file($request_url) or die("url not loading");
    
        $status = $xml->Response->Status->code;
        if (strcmp($status, "200") == 0) {
          // Successful geocode
          $geocode_pending = false;
          $coordinates = $xml->Response->Placemark->Point->coordinates;
          $coordinatesSplit = split(",", $coordinates);
    
          // Format: Longitude, Latitude, Altitude
          $lat = $coordinatesSplit[1];
          $lng = $coordinatesSplit[0];
    
        } else if (strcmp($status, "620") == 0) {
          // sent geocodes too fast, have a breather and try again soon
          echo("Google says no... increase the delay to ".($delay/1000000)." seconds<br />\n");
          $delay += 100000;
        } else {
          // failure to geocode
          $geocode_pending = false;
          echo "Address " . $address . " failed to be geocoded. ";
          echo "Received status " . $status . "<br />
    \n";
        }
        usleep($delay);
      }
      echo("Lat long found for " . $address . "<br />\n");
      echo("Lat: " . $lat . "<br />\n");
      echo("Long: " . $lng . "<br />\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my current code: $(#DialogScroll).dialog({ bgiframe: true, autoOpen: false, maxHeight: 600, width: 550, modal:
Here's the current code I am using. <? header(Content-type: image/png); // example: <img src=gradient.php?height=600&width=100&start=00FF00&end=ff0000
Here is my current code (that i am very proud of for my first
Here is my current code: $sql = SELECT * FROM user_posts; $result = mysql_query($sql);
Here is my current code (language is Python): newFrameImage = cv.QueryFrame(webcam) newFrameImageFile = cv.SaveImage(temp.jpg,newFrameImage)
Here's my current code: if (Key.isDown(Key.UP)) { //do stuff } What I want to
Here is the current code I am using: <UserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml x:Class=ButtonPrototype.MainPage Width=640 Height=480>
Here is my current code: RewriteCond %{HTTP_HOST} !^example\.com [NC] #RewriteCond %{REQUEST_URI}!^something RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
Here is my current code. I'm trying to display data from three separate queries
I been trying to do the question title. Here is my current code: Main.java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.