Asked  7 Months ago    Answers:  5   Viewed   34 times

i am using this api for getting current location but when this site goes down i am not able to get current location.

can google provide any api to find current location using ip.



If you don't want to use the HTML5 Geolocoation API, you can detect a bit from IP.

Or try other other solution

The Google Geocoding API




Wednesday, March 31, 2021
answered 7 Months ago

the solution of this question is

                    $url = str_replace(' ','-',$sport['title']);
                    $url = str_replace(":",'',$url);
                    $url = str_replace("'",'',$url);    

<a href="<?php echo base_url().'news/readmore/'.$sport['id']."/".urlencode($url);?>"><?php echo $sport_top['title'];?></a>
Wednesday, March 31, 2021
answered 7 Months ago

Modify your function to send header of JSON_DATA in post request

function sendPostData($url, $post){
 $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($post))                                                                       
  $result = curl_exec($ch);
  curl_close($ch);  // Seems like good practice
  return $result;

In file use



print_r( $json_input_data);


As everyone said there is no need of $str_data = json_encode($data);,Since data is already in json.

Wednesday, March 31, 2021
answered 7 Months ago

Make sure that you have added the service account as an Owner in Google Search Console as described here:

My problem was that we had multiple entries for the domain in the Search Console (with and without www and with and without https); after adding the service account as an owner to all 4 entries it's working.

Wednesday, March 31, 2021
answered 7 Months ago

The Google Contacts API uses an Atom feed. The contacts are provided as entry elements. So it makes more sense the iterate them. To do that you have to register a prefix for the atom namespace as well.

$document = new DOMDocument();
$xpath = new DOMXpath($document);
$xpath->registerNamespace('atom', '');
$xpath->registerNamespace('gd', '');

If you use DOMXpath::evaluate() you can use expressions that return scalars. The second argument is a context node for the expression.

foreach ($xpath->evaluate('/atom:feed/atom:entry') as $entry) {
  $contact = [
    'name' => $xpath->evaluate('string(atom:title)', $entry),
    'image' => $xpath->evaluate('string(atom:link[@rel=""]/@href)', $entry),
    'emails' => [],
    'numbers' => []
  foreach ($xpath->evaluate('gd:email', $entry) as $email) {
    $contact['emails'][] = $email->getAttribute('address');
  foreach ($xpath->evaluate('gd:phoneNumber', $entry) as $number) {
    $contact['numbers'][] = trim($number->textContent);

With the first example response from the Google Contacts API documentation this returns:

array(3) {
  string(17) "Fitzwilliam Darcy"
  string(64) ""
  string(0) ""
  array(1) {
    string(3) "456"

The example does not include an email element, so it is empty. A contact can have multiple email addresses and/or phone numbers or none at all. The rel attribute is provided to classify them as home, work, ...

Fetching the image:

The image is provided as an Atom link element with a specific rel attribute.


This would return the link node, but it is possible to fetch the href attribute directly:


Cast the attribute node list into a string:


Wednesday, March 31, 2021
answered 7 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :