簡體   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;
    }
  }

我正在使用上面的代碼段通過Google Place API添加一個地點。 但是我遇到一個錯誤

SSL certificate problem: unable to get local issuer certificate

當我使用codeigniter框架時,我需要在框架中添加一些庫。 實際上,我是第一次嘗試這種情況,並且研究了以下文檔

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

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

並嘗試將流程集成到PHP中。 我怎樣才能做到這一點。

添加此行:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

避免進行證書檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM