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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:56:29+00:00 2026-05-30T09:56:29+00:00

I’ve got some code that takes any address and returns lat and long as

  • 0

I’ve got some code that takes any address and returns lat and long as a php variable.

if ($_SESSION['where']) {
    $where = stripslashes($_SESSION['where']);
    $whereurl = urlencode($where);

$location = file("http://maps.google.com/maps/geo?q=new+york+New+york
&output=csv&key=xxxxxxxxxxxxxxxxxxxxxxxx");
        list ($stat,$acc,$north,$east) = explode(",",$location[0]);
        $html = "Information for ".$where."<br>";
        $html .= "North: $north, East: $east<br>";
        $html .= "Accuracy: $acc, Status: $stat<br>";
} else {
        $html = "Varibles Undefined";
}

?>


     <?php $_SESSION['lat'] = "$html"; $_SESSION['lon'] = "$whereurl"; echo"<strong>"?><?php echo "$north";?>&deg; North, <?php echo "$east";?>&deg; East</strong>

I know it works because when I enter

http://maps.google.com/maps/geo?q=$whereurl
    &output=csv&key=xxxxxxxxxxxxxxxxxxxx

manually into a browser, it returns

200,4,40.7143528,-74.0059731

which is what I need saved as a PHP variable. However it’s not saving it as $north or $east. Any suggestions on how to fix this? Thank’s in advance.

here’s what it gives me:

{ “name”: “new york new york”, “Status”: { “code”: 200, “request”: “geocode” }, “Placemark”: [ { “id”: “p1”, “address”: “New York, NY, USA”, “AddressDetails”: { “Accuracy” : 4, “Country” : { “AdministrativeArea” : { “AdministrativeAreaName” : “NY”, “SubAdministrativeArea” : { “Locality” : { “LocalityName” : “New York” }, “SubAdministrativeAreaName” : “New York” } }, “CountryName” : “USA”, “CountryNameCode” : “US” } }, “ExtendedData”: { “LatLonBox”: { “north”: 40.8495342, “south”: 40.5788964, “east”: -73.7498543, “west”: -74.2620919 } }, “Point”: { “coordinates”: [ -74.0059731, 40.7143528, 0 ] } }, { “id”: “p2”, “address”: “Manhattan, New York, NY, USA”, “AddressDetails”: { “Accuracy” : 4, “Country” : { “AdministrativeArea” : { “AdministrativeAreaName” : “NY”, “SubAdministrativeArea” : { “Locality” : { “DependentLocality” : { “DependentLocalityName” : “Manhattan” }, “LocalityName” : “New York” }, “SubAdministrativeAreaName” : “New York” } }, “CountryName” : “USA”, “CountryNameCode” : “US” } }, “ExtendedData”: { “LatLonBox”: { “north”: 40.8200450, “south”: 40.6980780, “east”: -73.9033130, “west”: -74.0351490 } }, “Point”: { “coordinates”: [ -73.9662495, 40.7834345, 0 ] } } ] }

  • 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-30T09:56:30+00:00Added an answer on May 30, 2026 at 9:56 am

    Use file_get_contents instead (which returns you a string).

    Short Example:

    $location = file_get_contents("http://maps.google.com/maps/geo?q=$whereurl&output=csv");
    $test = explode(",",$location);
    print_r($test);
    

    Full Solution here:

    http://www.ece.uvic.ca/~casualt/random.php?location=Bermuda

    Source:

    $theLocation = "new+york";
    $locIn = $_GET['location'];
    if($locIn)
    {
        $theLocation = urlencode($locIn);   //Just to be safe (even though this got passed in via get
    }
    $location = file_get_contents('http://maps.google.com/maps/geo?q='.$theLocation.'&output=csv&key=AIzaSyAQtiJHUt5KiL-aGONLlACQQ3OdwpbvFzI');
    $test = explode(",",$location);
    //print_r($test);
    $lat = $test[2];
    $long = $test[3];
    echo '<h1>Magical Location of '.$theLocation.':</h1>';
    echo '<ul>';
    echo '<li>Longitude: '.$long.'</li>';
    echo '<li>Latitude: '.$lat.'</li>';
    echo '</ul>';
    

    That should do the trick for you. 🙂

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.