简体   繁体   English

在PHP中使用Google Place API添加位置

[英]Adding place using google place api in PHP

<?php

class MyClass Extends CI_controller{

public function index(){

    $jsonpost = '{
                  "location": {
                    "lat": -33.8669710,
                    "lng": 151.1958750
                  },
                  "accuracy": 50,
                  "name": "Google Shoes!",
                  "phone_number": "(02) 9374 4000",
                  "address": "48 Pirrama Road, Pyrmont, NSW 2009, Australia",
                  "types": ["shoe_store"],
                  "website": "http://www.google.com.au/",
                  "language": "en-AU"
                }';

    $url = "https://maps.googleapis.com/maps/api/place/add/json?key=AIzaSyCuM8rztQMtRpD2ivmjgJaLZgWloyq12l4";
    $results = $this->ProcessCurl ($url, $jsonpost);
    echo $results."<BR>";
  }

  public function ProcessCurl($URL, $fieldString){ //Initiate Curl request and send back the result  
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_URL, $URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    //curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldString);
    $resulta = curl_exec ($ch);
    if (curl_errno($ch)) {
            print curl_error($ch);
    } else {
    curl_close($ch);
    }
    echo $resulta;
    }
  }

I'm using the above code snippet to add a place with google place api. 我正在使用上面的代码段通过Google Place API添加一个地点。 But i'm getting an error 但是我遇到一个错误

SSL certificate problem: unable to get local issuer certificate

as i am using codeigniter framework do I need to add some library in the framework. 当我使用codeigniter框架时,我需要在框架中添加一些库。 Actually I'm trying this for the first time and I studied the following documentations 实际上,我是第一次尝试这种情况,并且研究了以下文档

https://developers.google.com/places/documentation/search#PlaceSearchRequests https://developers.google.com/places/documentation/search#PlaceSearchRequests

https://developers.google.com/places/documentation/actions#place https://developers.google.com/places/documentation/actions#place

and trying to integrate the process in PHP. 并尝试将流程集成到PHP中。 How can I do that. 我怎样才能做到这一点。

Add this line: 添加此行:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

to avoid certificate checks. 避免进行证书检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM