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

  • SEARCH
  • Home
  • 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 7927417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:18:04+00:00 2026-06-03T19:18:04+00:00

hi i am trying to get latitude and longitude values by address function get_lat_long_from_address($address)

  • 0

hi i am trying to get latitude and longitude values by address

function get_lat_long_from_address($address)
{

    $lat = 0;
    $lng = 0;

    if ($this->geocodeCaching) { // if caching of geocode requests is activated

        $CI =& get_instance();
        $CI->load->database(); 
        $CI->db->select("latitude,longitude");
        $CI->db->from("geocoding");
        $CI->db->where("address", trim(strtolower($address)));
        $query = $CI->db->get();

        if ($query->num_rows()>0) {
            $row = $query->row();
            return array($row->latitude, $row->longitude);
        }

    }

    $data_location = "http://maps.google.com/maps/api/geocode/json?address=".str_replace(" ", "+", $address)."&sensor=".$this->sensor;
    if ($this->region!="" && strlen($this->region)==2) { $data_location .= "&region=".$this->region; }
    $data = file_get_contents($data_location);

    $data = json_decode($data);

    if ($data->status=="OK") {

        $lat = $data->results[0]->geometry->location->lat;
        $lng = $data->results[0]->geometry->location->lng;

        if ($this->geocodeCaching) { // if we to need to cache this result
            $data = array(
                "address"=>trim(strtolower($address)),
                "latitude"=>$lat,
                "longitude"=>$lng
            );
            $CI->db->insert("geocoding", $data);
        }

    }

    return array($lat, $lng);

}

the thing is whatever th address i pass to the function it returns only (0,0) for latitude and longitude .

i passed the address like

$address = "colombo,sri lanka"; 
$address = "colombo,LK";
$address = "newyork,United states";
$address = "1/35 amunugama gunnena,kandy,sri lanka";

but every time it returns (0,0) ,

why is this , what is the address format i need to use , please help . thanks in advance ………

  • 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-06-03T19:18:06+00:00Added an answer on June 3, 2026 at 7:18 pm

    I am not sure what value and URL you are getting exactly, so I tried in the browser with your input URL

    http://maps.google.com/maps/api/geocode/json?address=colombo,sri+lanka&sensor=true

    which gives the correct result.

    Make sure your URL is creating correctly.

    To see the output for debug, you can print like
    print_r ($data);

    Also the suggestion is put the CodeIgniter in your tag list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the users current latitude and longitude with this viewDidLoad method.
Im trying to implement the geolocation services to get the latitude and longitude values,
I'm trying to get longitude and latitude values from the google maps api with
Sometimes when trying to get the Latitude span or Longitude span of a mapview
I'm receiving deserialized object using WCF (trying to get latitude and longitude using google
I am trying to get the current longitude and latitude right before the table
I'm trying to get rough greater than and less than values to compare latitude
I'm trying to load latitude and longitude value using this code but I receive
I am trying to get value (says phone number) based on latitude and longitude
I am trying to reverse geocode the latitude and longitude of my google maps

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.