Google映射Geo反向位置循环&时间间隔

时间:2014-10-21 13:50:03

标签: javascript php angularjs google-maps-api-3 geolocation

我想做的是。我阅读了关于警察报告等的RSS提要。代码每30秒刷新一次rss页面,并将所有数据添加到数据库中,并使用lon& amp; LAT。

问题是,我想使用反向地理位置获取街道地址。它工作得很好,但它只给出了php循环中最后一项的地址。有没有办法可以使用下面的代码到达所有街道?

    $xml=("http://feeds.livep2000.nl");

function getFeed($feed_url) {

    $content = file_get_contents($feed_url);
    $x = new SimpleXmlElement($content);
    $conn = new Connection; 
    $x->registerXPathNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
    $x->registerXPathNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
    $x->registerXPathNamespace('geo', 'http://www.w3.org/2003/01/geo/wgs84_pos#'); 
    $i = 0;
    foreach($x->channel->item as $entry) 
    {
        $geolat = $entry->xpath('geo:lat');
        $geolon = $entry->xpath('geo:long');
        if($geolat != "" && $geolon != ""){
            $checkifexists = $conn->query("SELECT `alerts` FROM `alerts_p2000` WHERE `lat` = '".$geolat[0]."' AND `lon` = '".$geolon[0]."'");
            if($checkifexists->num_rows == '0')
            {

                $sql = "INSERT INTO `alerts_p2000` (`title`,`lat`,`lon`,`date_added`,`cat`)
                VALUES ('".$conn->real_escape_string($entry->title)."','".$geolat[0]."','".$geolon[0]."',now(),'68')";
                $conn->query($sql);
                $alert_id = $conn->inserted_id();

                $description = "<b>".$conn->real_escape_string($entry->description)."</b>";
                $sql = "INSERT INTO `alerts_content_p2000` (`description`,`alert_id`,`img`)VALUES('".$description."','".$alert_id."','68/politie')";
                $conn->query($sql);
                $alertcontent_id = $conn->inserted_id();

                $sql = "UPDATE `alerts_p2000` SET `alert_content_id` = '".$alertcontent_id."' WHERE `alerts` = '".$alert_id."'";
                $conn->query($sql);
                $i++;

                ?>
                <script>
                    console.log('test');

                    var app = angular.module('app', []);

                    app.controller('mainctrl', function($scope, $filter) 
                    {
                        ///// HIER DE CODE
                        $scope.alerts = {};
                        $scope.alerts.lat = <?php echo $geolat[0]; ?>;
                        $scope.alerts.lon = <?php echo $geolon[0]; ?>;
                        console.log($scope.alerts);
                        var geocoder = new google.maps.Geocoder();
                        var yourLocation = new google.maps.LatLng($scope.alerts.lat, $scope.alerts.lon);
                        console.log('first test');

                        geocoder.geocode({ "latLng": yourLocation }, function (results, status) 
                        {
                            if(status == google.maps.GeocoderStatus.OK) 
                            {
                                if(results[0]) 
                                {
                                    var numberobj = $filter('filter')(results[0].address_components, {types: "street_number"})[0];
                                    $scope.alerts.number = numberobj.long_name;

                                    var streetobj = $filter('filter')(results[0].address_components, {types: "route"})[0];
                                    $scope.alerts.street = streetobj.long_name;

                                    var cityobj = $filter('filter')(results[0].address_components, {types: "locality"})[0];
                                    $scope.alerts.city = cityobj.long_name;
                                    $scope.$apply();

                                    console.log('' + $scope.alerts.street + ' ' + $scope.alerts.city);
                                }
                            }
                        });
                    });

                    </script>
                <?

            }   
        }
    }
    echo $i.' nieuwe alerts';
}

echo getFeed($xml);

假设我有4个新的Feed项,代码显示'test'4次但地址只有一次

编辑:所以有了新的信息,我想找到一种方法,通过timerinterval将请求限制为每秒一次,但是设置时间间隔或超时对我来说不起作用

0 个答案:

没有答案
相关问题