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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:28:32+00:00 2026-06-07T02:28:32+00:00

I got the following piece of code, but it doesn’t seem to get the

  • 0

I got the following piece of code, but it doesn’t seem to get the right values for lat and long. It gives me 0,000000 in return. When I check an adress, it gives me the right values in the json.

mysql_select_db($dbname);

$result = mysql_query("SELECT id, street, postalcode, place, lat, lng FROM stores") or die(mysql_error());  

while($row = mysql_fetch_array( $result )){

$addressbar = $row['street']." ".$row['postalcode']." ".$row['place'];

$address = urlencode($addressbar);

$json = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=true");
$decoded = json_decode($json);

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

mysql_query("UPDATE stores SET lat='$lat', lng='$lng' WHERE id=".$row['id']."") or die(mysql_error());
printf( $addressbar."%d\n", mysql_affected_rows());
echo "<br/><br/>";
}

I can’t seem to find what I’m doing wrong. I hope anyone can help me out.

  • 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-07T02:28:34+00:00Added an answer on June 7, 2026 at 2:28 am

    A few things! To debug, I would do the following:

    1. Ensure that use strict; & use warnings; is at the top of your code (you probably did this, but it doesn’t show i nthe snippet).
    2. I would print out $json, if you are getting 0’s back from the map api, you may be able to see an error msg back in the $json text. If you are getting lat/lng in $json, then add more debugging to your mysql query or print out the query before it goes to the exec function. For example to add more debugging:

      DBI->connect( $dsn, $username, $password, { 'PrintError' => 1 } )
      
    3. If it is not in $json, then I would manually go to the map api URL to see what I get back

    4. I’m guessing that you removed it from the URL above(i see no &key=AAABB…..), but double check your maps API key is correct
    5. I’m sure you trust the data back from google, but please get in the habit of using placeholders when doing any query. Placeholders (?) instead of putting the variables directly in the SQL code protect you from SQL injection. Ex:

      $mysqlquery = $dbh->prepare( 'UPDATE stores SET lat=?, lng=? WHERE id=?' );
      $mysqlquery->execute( $lat, $lng, $row['id'] );
      
    6. Sometimes it helps me when I am debugging to print out what I am about to send to an API. Instead of sending the URL or query directly to the function, put it in a variable, print that variable out, then send the variable to the function/api. You may be assuming that it is correct, but some small issue is preventing it from working that is obvious if you see the string.

    Hope this all helps a bit, good luck!

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

Sidebar

Related Questions

I've got the following piece of code, but I can't find how to get
I've got the following piece of code: ... int x = 0; int y
in the following piece of code I got from a book. The NSString *pPath
I got following code from net and it looks everything is proper but i'm
I've got the following piece of code on a PHP 5.2.4 (no safe_mode) linux
I've got a piece of code that's automatically generated that compiles on Linux but
I'm not sure what I'm doing wrong, but I've got a piece of code
I've got a piece of code that returns a super-long string that represents search
I'm experimenting with pthread library and I've got the following piece of code: for
I've got the following piece of code that implements a monad. I'm trying to

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.