Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to get current location latitude and longitude in php

function geoLocate($address)
{
    try {
        $lat = 0;
        $lng = 0;

        $data_location = "https://maps.google.com/maps/api/geocode/json?key=".$GOOGLE_API_KEY_HERE."&address=".str_replace(" ", "+", $address)."&sensor=false";
        $data = file_get_contents($data_location);
        usleep(200000);
        // turn this on to see if we are being blocked
        // echo $data;
        $data = json_decode($data);
        if ($data->status=="OK") {
            $lat = $data->results[0]->geometry->location->lat;
            $lng = $data->results[0]->geometry->location->lng;

            if($lat && $lng) {
                return array(
                    'status' => true,
                    'lat' => $lat, 
                    'long' => $lng, 
                    'google_place_id' => $data->results[0]->place_id
                );
            }
        }
        if($data->status == 'OVER_QUERY_LIMIT') {
            return array(
                'status' => false, 
                'message' => 'Google Amp API OVER_QUERY_LIMIT, Please update your google map api key or try tomorrow'
            );
        }

    } catch (Exception $e) {

    }

    return array('lat' => null, 'long' => null, 'status' => false);
}
Comment

PREVIOUS NEXT
Code Example
Php :: unset by key name php 
Php :: Sending Data over another website via PHP 
Php :: crul in laravel 
Php :: access json object in php 
Php :: laravel 8: bootstrap 
Php :: store multiple session in laravel 
Php :: offset codeigniter 3 
Php :: php.ini location 
Php :: create function php 
Php :: array prepend php 
Php :: <a href="<?php echo base_url(); ?"somelink</a 
Php :: get featured image id wordpress 
Php :: comparing floats php 
Php :: laravel-medialibrary packagist 
Php :: custom 404 page in laravel 
Php :: php get highest key in array 
Php :: automatically make created_by and updated_by laravel 
Php :: php count matching words in two strings 
Php :: print only some characters of a string in php 
Php :: steps to create laravel project 
Php :: php check if entire array are in another array 
Php :: php recursive function to build array 
Php :: php convert to boolean 
Php :: remove first 4 characters in string php 
Php :: woocommerce add to cart hook 
Php :: php ofreach 
Php :: laravel tree category 
Php :: php array_map() 
Php :: artisan make migration with model 
Php :: générer des nombres aléatoires décimaux en php 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =