0

我一直在试图弄清楚如何对我的页面进行编码,以便在我的表单中输入答案时,它会通过谷歌地图 API 搜索该答案。我似乎无法正确编码,对于我如何实现目标的任何帮助将不胜感激!谢谢。

<head>
        <!-- This is my first trashy online quiz! -->
            <title>Extra Quiz Information</title>
</head>
<body>
    <h1> More about your quiz results!</h1>
    <?php 
        if (isset($_COOKIE['visit_id'])){
            $visit_id = $_COOKIE['visit_id'];
            $all_variables = json_decode(file_get_contents("/var/www/html/data/$visit_id.json"), TRUE);
            //var_dump ($all_variables); 
            echo "<p>";
                echo "Our results show that when you took the quiz: What Environment Suits You? on "; echo $all_variables['timestamp'];
                echo ", <br>you expressed that your favorite place to be in the whole world was: "; echo $all_variables['answer1']; 
            echo "</p>";

            $google_map_stuff = json_decode(file_get_contents echo <a href="http://maps.googleapis.com/maps/api/geocode/json?address=', urlencode($all_variables['answer1'])">, TRUE);
            echo $google_map_stuff["results"][0]["types"][0];
            //var_dump($google_map_stuff);
        } else {
            echo "You have not yet taken the quiz titled: What Environment Suits You?<br>
            Please "; echo '<a href="roate1-form.html">take it now</a>'; echo " and then return to this page after you have finished.";
        }

                ?>

</body>

4

1 回答 1

0

你有错误信息吗?你真的不应该像现在这样调用 API。如果你想使用 Web 服务 API,你应该从你的服务器上做。否则,如果您想使用 Javascript,请查看Google Maps Javascript API 参考(我将您直接链接到地理编码器参考.

我不会对我的代码感到厌烦,而是为您提供指向Google 代码示例页面的直接链接。

于 2012-04-30T04:10:30.377 回答