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 6146475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:57:19+00:00 2026-05-23T18:57:19+00:00

Here is my function: <?php function latLng($str){ $address = $str; // Initialize delay in

  • 0

Here is my function:

<?php
function latLng($str){
    $address = $str;
    // Initialize delay in geocode speed
    $delay = 0;
    $base_url = "http://maps.google.com/maps/geo?output=xml&key=" . $key;

    // Iterate through the rows, geocoding each address
    $geocode_pending = true;
    $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
        $delay += 100000;
    } else {
        // failure to geocode
        $geocode_pending = false;
        echo "Address " . $address . " failed to geocoded. ";
        echo "Received status " . $status . "\n";
        usleep($delay);
    }
    echo $lat . "<br />";
    echo $lng;
}

echo latLng("Praha City Center, Klimentska 46, Prague, Czech Republic, 11002");
?>

It echos the lat and lng on page perfectly, but I want to return them as variables, so basically I wrap an address in the function and then a $lat and a $lng variable are returned to the page for me to use.

How do I go about doing this?

Thank you

  • 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-23T18:57:20+00:00Added an answer on May 23, 2026 at 6:57 pm

    Two options:

    1. Return $coordinatesSplit array instead and print its elements when required
    2. Make two by-ref parameters to the function:

      function latLng($str, &$lat, &$lng) {
        //.....
         $lat = $coordinatesSplit[1];
         $lng = $coordinatesSplit[0];
        // ....
      }
      

    then use them:

         $lat = $lng = null;
         latLng("Praha City Center, Klimentska 46, Prague, Czech Republic, 11002", $lat, $lng);
         echo $lat;
         echo $lng; // or whatever you want to do with them
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm kind of stuck with my heap sort here in php: <?php function heapSort($a,
Here is the code: $('#sousmenu a').click (function (){ startSlideshow(<?php echo json_encode(glob(photos- .$_GET[folder]. /*.jpg));?>); return
Here's my Zend code: <?php require_once ('Zend\Form.php'); class Sergio_Form_registrationform extends Zend_Form { public function
So what I'm looking for here is something like PHP's print_r function. This is
What is the alternative to the deprecated function session_is_registered() in PHP 5? Here's my
I am completely stumped. Here is my php (CodeIgniter) code: function mod() { $uid
I have a ajax image upload script which i found here http://www.fengcool.com/2009/06/ajax-form-upload-local-image-file-without-refresh/ The problem
A function call in PHP is expensive. Here is a small benchmark to test
I'm currently working on a Google Maps project and am implementing a search function.
I have the following php code which I found here : function download_xml() {

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.