0

So I am trying to add a place to a google map using the places api however from what I have found is that jquery and javascript use jsonp and there is no support for this in the places api. Therefore I tried doing it in php but I have little experience with php and was only able to make the post request using CURL. It was successful and I was able to create the place and print the json. What I want to know is if there is a way to obtain the data for the place to be created using javascript or jquery and then make a json post request which would pass on the places information to the php file and then make the json post request from there and then return the json to the javascript file?

This is what I have for the php file so far,

<?php
    function ProcessCurl($URL, $fieldString){
             $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_POSTFIELDS, $fieldString);
             $resulta = curl_exec ($ch);
     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/jsonsensor=false&key=YOUR_API_KEY";
    $results = ProcessCurl($url, $jsonpost);
    echo $results. "<BR>";
 ?>

Therefore I need to be able to pass on the json data to the variable $jsonPost and return the correct json data back to the javscript file.

2 Answers 2

0

Yes, convert to to a php array, then to a json array

http://php.net/manual/en/function.json-encode.php

http://www.php.net/manual/en/function.json-decode.php

0

It's hard to understand what you're asking. Are you asking...

  • How to get the place information from a webpage?

If so, what are you using as an interface?

  • How to get your webpage to post to your php file?

If so, you can populate a form pointing to your PHP file and then submitting the information.

  • Something else?

Your question is a bit unclear.

2
  • Ok I need to know how to turn the data: paramater used in the ajax post call to my php page into a json file that i can then use instead of $jsonpost to complete my call to ProcessCurl Nov 14, 2012 at 23:28
  • What "data" parameter? Are you referring to jQuery's $.post() call? If so, read the documentation, as there is a bunch of stuff you will need to know: api.jquery.com/jQuery.ajax. To start, scroll down to the "data" field and read what it says. Nov 19, 2012 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.