Jump to content

City/State by zip not working on webhost


lovephp
Go to solution Solved by lovephp,

Recommended Posts

friend the following code fetches city state etc from google by zip or postcode which works fine on my localhost wamp server but when i try it online on my webhost nothing is showing, how can i fix it please?

 

        $search_code = urlencode($row['zip']);
        $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $search_code . '&sensor=false';
        $json = json_decode(file_get_contents($url));
        $lat = $json->results[0]->geometry->location->lat;
        $lng = $json->results[0]->geometry->location->lng;
        $address_url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $lng . '&sensor=false';
        $address_json = json_decode(file_get_contents($address_url));
        $address_data = $address_json->results[0]->address_components;
        $street = str_replace('Dr', 'Drive', $address_data[1]->long_name);
        $town = $address_data[2]->long_name;
        $county = $address_data[3]->long_name;

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.