MongoDB: Geospatial Index array not in correct format

橙三吉。 提交于 2019-12-05 19:42:57

Mongodb expects numbers for the coordinates while you passed in a string.

"Location" : {
                       "Longitude" : 50.0, // <<<<<<<<<<<<<< use numbers instead
                       "Latitude" : 50.0
               },

see http://www.mongodb.org/display/DOCS/Geospatial+Indexing for details.

The problem has been fixed by converting the Location parameters into a float type like this.

$var = $JSonString['Places'];
 $test=count($var);

 $i=0;
 for ( $i=0; $i<$test;$i++){
       $lon = (float)$JSonString['Places'][$i]['Location']['Longitude'];
       $lat = (float)$JSonString['Places'][$i]['Location']['Latitude'];
       $JSonString['Places'][$i]['Location']['Longitude'] =$lon ;
       $JSonString['Places'][$i]['Location']['Latitude'] =$lat ;
       //error_log($lon . "->".gettype($JSonString['Places'][$i]['Location']['Latitude']), 3 , "/var/tmp/my-errors.log");
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!