title: PHP code for adding new place to Google Places via API
body: <p>I'm working on integrating Google's Places API into a web app.  I've been able to successfully create code to allow users to search for places using the API and to display results in the app, so that's cool.  </p>
  
  <p>What I haven't been able to figure out is how to allow users of the app to add new places.  Something which Google says is doable.  They have some documentation on it here - </p>
  
  <p><a href="https://code.google.com/apis/maps/documentation/places/#adding_a_place" rel="noreferrer">https://code.google.com/apis/maps/documentation/places/#adding_a_place</a></p>
  
  <p>But no example code and I'm having some difficulty working out PHP code to implement the add call.  </p>
  
  <hr>
  
  <p>This is the code that I've come up with so far. I've replaced my actual API key with {your key} here.</p>
  
  <p>I keep getting a malformed post error - </p>
  
  <p><em>400. That’s an error.
  Your client has issued a malformed or illegal request. That’s all we know.</em> </p>
  
  <hr>
  
  <pre><code>&lt;?php
  
  function ProcessCurl($URL, $fieldString){ //Initiate Curl request and send back the result
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_HTTPHEADERS, array('Content-Type: application/json'));
          curl_setopt($ch, CURLOPT_URL, $URL);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
          curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
          curl_setopt($ch, CURLOPT_POSTFIELDS, array('json'=&gt;json_encode($fieldString)));
          $resulta = curl_exec ($ch);
          if (curl_errno($ch)) {
                  print curl_error($ch);
          } else {
          curl_close($ch);
          }
          echo $resulta;
      }
  
  $jsonpost = '{
    "location": {
      "lat": -33.8669710,
      "lng": 151.1958750
     },
    "accuracy": 50,
     "name": "Daves Test!",
     "types": ["shoe_store"],
    "language": "en-AU"
  }';
   $url = "https://maps.googleapis.com/maps/api/place/add/json?sensor=false&amp;key={your key}";
  
   $results = ProcessCurl ($url, $jsonpost);
  
   echo $results."&lt;BR&gt;";
  ?&gt; 
  </code></pre>