Google Map ApiPhp

How to get the latitude and longitude using curl php?

get the latitude and longitude using curl php

Php Preg_Match Pattern for Week Days Name
817Views

Hello, welcome to therichpost.com. In this post, I will tell you,  How to get the latitude and longitude using curl php? I personally like php ver much. PHP is the best web language. There are many cms and frameworks in PHP and WordPress is the best example. facebook also used PHPin it.

Today, we will get lat-long with the help of php curl function.

google-lat-long

Here is the working code  and you have to enable curl on your system if it will not work:
<?php
  $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=ludhiana&sensor=false";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $details_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  $geoloc = json_decode(curl_exec($ch), true);
  switch ($geoloc[‘status’]) {
    case 'ZERO_RESULTS':
      return 0;
      break;
    case 'OK':
      print_r($geoloc['results'][0]['geometry']['location']);
      break;
  }
             ?>

 There are so many code in PHP and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

Positive SSL