0

我对“foreach”有点麻烦。测试页面显示:

*Warning: Invalid argument supplied for foreach() in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 60*

*Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 64*

*Warning: Invalid argument supplied for foreach() in /data/web/virtuals/23481/virtual/www/subdom/vsohbrno/poi/junaio/junaio/test.php on line 68*

但是,我为 Junaio(智能手机的 AR 应用程序)制作了它——当我尝试在此处(在应用程序中)运行它时,我没有遇到任何问题——它正在工作。但是,如果警告也会在 www 页面中消失,那很好 =o)

我的源代码:

<?php

require_once '../ARELLibrary/arel_xmlhelper.class.php';

if(!empty($_GET['l']))
    $position = explode(",", $_GET['l']);
else
    trigger_error("user position (l) missing. For testing, please provide a 'l' GET parameter with your request. e.g. pois/search/?l=23.34534,11.56734,0");

//create the xml start
ArelXMLHelper::start(NULL, "/arel/index.html");

//start by defining some positions of geo referenced POIs and give those names and thumbnails
$treasureLocations = array(  
    array("48.6045911000,14.7007322000,0", "Tradiční výroba marmelád a povidel ", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Pohorská Ves."),  
    array("48.6438239000,14.2208661000,0", "Restaurace Czech Specials (Restaurace Lanovka)", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Lipno nad Vltavou."),  
    array("48.6541914000,14.0354000000,0", "Plavení dřeva, vorařství – Schwarzenberský plavební kanál", "Jih Čech > Šumava > Šumava a Pošumaví. Obec: Přední Výtoň."),  
);

//in the filter_value, the continent parameter will be send from the client, once the continent is filtered
$filter = $_GET['filter_value'];

//display the POIs as defined in the Constructor
$countpoi = 1;
foreach($treasureLocations as $i => $findPOI)
{    
  //Parameters for distance calculate. $Location = GPS coordinates of the POI, $Position = my GPS position. 
  $location = explode(",", $findPOI[0]);

  //Calculate distance beween my position and POI
  $deg2RadNumber = (float)(pi() / 180); 
  $earthRadius= 6371.009; 
  $latitudeDistance=((float)$position[0]-(float)$location[0])*$deg2RadNumber; 
  $longitudeDistance=((float)$position[1]-(float)$location[1])*$deg2RadNumber; 
  $a=pow(sin($latitudeDistance/2.0),2) +  cos((float)$position[0]*$deg2RadNumber) * cos((float)$location[0]*$deg2RadNumber) * pow(sin($longitudeDistance/2.0),2); 
  $c=2.0*atan2(sqrt($a),sqrt(1.0- $a)); 
  $distance=round($earthRadius*$c); 


  //Set distance for displaying objects (in kilometers)
  if($distance < 10)
  {    
    $title = $findPOI[1];   //Title of the POI
    $poi[$countpoi]['attribution'] = $findPOI[2]; //Description of the POI  
    $poi[$countpoi]['distance'] = $distance; // Distance between POI and me 

    //create the POI
    $poi[$countpoi]['poi'] = ArelXMLHelper::createLocationBasedPOI($i, $title, explode(",", $findPOI[0]), "http://vsohbrno.chudst.cz/poi/poi_obrazek.png", "http://vsohbrno.chudst.cz/poi/poi_obrazek.png", $poi[$countpoi]['attribution'], NULL);    
    $countpoi++;
   }
}       

  //Sorting POI (the closest -> the furthest)      
  foreach ($poi as $val)
  {
    $sortarray[] = $val['distance'];
  }
  array_multisort($sortarray,$poi);


  //Write 39 POI to XML file
  foreach ($poi as $POInumber => $POIvalue)
  {
    if($POInumber < 39){
     if(!empty($filter))
     {
        if(strtolower($filter) == strtolower($poi[$POInumber]['attribution']))
        {
            ArelXMLHelper::outputObject($poi[$POInumber]['poi']); 
        }       
    } 
     else
         {ArelXMLHelper::outputObject($poi[$POInumber]['poi']);}
    }     
  } 



//end the output
ArelXMLHelper::end();

?>
4

1 回答 1

1

如果距离从不小于 10 公里,$poi则不会初始化,这就是错误的含义。

初始化$poi为一个数组,它应该删除警告:

$poi = array();
于 2014-01-01T14:00:21.600 回答