需要使用Google地图API的帮助

时间:2012-04-30 04:03:30

标签: api google-maps

我一直在试图弄清楚如何对我的网页进行编码,以便在我的表单中输入答案时,它会通过Google地图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>

1 个答案:

答案 0 :(得分:0)

您有错误消息吗?你真的不应该像你那样调用API。如果要使用Web服务API,则应从服务器执行此操作。否则,如果您想使用Javascript,请查看Google Maps Javascript API reference (I linked you straight to the geocoder reference

我不会厌恶我的代码,而是直接链接到Google code samples page.