php请求返回GeoJSON格式的数据
<?php /*
* Following code will list all the products
*/ // array for JSON response
$response = array(); // include db connect class
require_once __DIR__ . '/db_connect.php'; // connecting to db
$db = new DB_CONNECT(); // get all products from products table
$result = mysql_query("SELECT * FROM fbteam") or die(mysql_error()); # Build GeoJSON feature collection array
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
); // check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node while ($row = mysql_fetch_array($result)) {
$feature = array(
'id' => $row['id'],
'type' => 'Feature',
'geometry' => array(
'type' => 'Point',
# Pass Longitude and Latitude Columns here
'coordinates' => array($row['lon'], $row['lat'])
)
);
# Add feature arrays to feature collection array
array_push($geojson['features'], $feature);
}
header('Content-type: application/json');
header("Access-Control-Allow-Origin: *");
echo json_encode($geojson, JSON_NUMERIC_CHECK);
} else {
echo "no data";
}
mysql_close($con);
db_connect.php
<?php /**
* A class file to connect to database
*/
class DB_CONNECT { // constructor
function __construct() {
// connecting to database
$this->connect();
} // destructor
function __destruct() {
// closing db connection
$this->close();
} /**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php'; // Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error()); // Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error()); // returing connection cursor
return $con;
} /**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
} }
config中配置数据库连接的信息
<?php /*
* All database connection variables
*/ define('DB_USER', "root"); // db user
define('DB_PASSWORD', "mypassword"); // db password
define('DB_DATABASE', "mydatabase"); // database name
define('DB_SERVER', "localhost"); // db server
?>
php请求返回GeoJSON格式的数据的更多相关文章
- springmvc通过ajax异步请求返回json格式数据
jsp 首先创建index.jsp页面 <script type="text/javascript"> $(function () { $("#usernam ...
- 3.自定义返回json格式的数据给前台(自定义Controller类中的Json方法)
在mvc的项目中,我们前台做一些操作时,后台要返回一些结果给前台,这个时候我们就需要有一个状态来标识到底是什么类型的错误, 例如: 执行删除的时候,如果操作成功(1行受影响),我们需要返回状态为1并输 ...
- SSH返回Json格式的数据
在开发中我们经常遇到客户端和后台数据的交互,使用比较多的就是json格式了.在这里以简单的Demo总结两种ssh返回Json格式的数据 项目目录如下 主要是看 上图选择的部分 WebRoot里面就 ...
- WebAPI搭建(二) 让WebAPI 返回JSON格式的数据
在RestFul风格盛行的年代,对接接口大多数人会选择使用JSON,XML和JSON的对比传送(http://blog.csdn.net/liaomin416100569/article/detail ...
- 人人商城返回Json格式的数据
人人商城返回Json格式的数据 1.找到该插件对应的 core/mobile 路径 2.新建一个 api.php 文件 <?php header('Content-Type:applicatio ...
- Golang-Gin Response 统一返回restful格式的数据
目的: gin返回restful格式的数据,返回的200,201 的数据 也包括异常时的404/500等情况 直接调用即可 package response import ( "github ...
- 使用jQuery发送POST,Ajax请求返回JSON格式数据
问题: 使用jQuery POST提交数据到PHP文件, PHP返回的json_encode后的数组数据,但jQuery接收到的数据不能解析为JSON对象,而是字符串{"code" ...
- asp.net MVC控制器中返回JSON格式的数据时提示下载
Asp.net mvc在接收的是JSON格式的数据,但是奇怪的是在IE中提示下载文件,其他浏览器中一切正常,下载后,里面的内容就是在控制器中返回的数据.代码如下: 视图中js代码: $("# ...
- 用shp制作geoJson格式地图数据(shp convert to geoJson)
本文紧接前文,简单说明利用shp数据制作Echarts支持的geoJson格式的地图数据.本文以北京市通州区各镇的shp数据为例进行说明. 软件环境: ArcGIS 10.2 (ArcGIS 10.2 ...
随机推荐
- 安装springboot时遇到 LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.问题
将工程外部jar包删除slf4j就可以运行.
- 机器学习实战(一)kNN
$k$-近邻算法(kNN)的工作原理:存在一个训练样本集,样本集中的每个数据都存在标签,即我们知道样本集中每一数据与所属分类的对于关系.输入没有标签的新数据后,将新数据的每一个特征与样本集中数据对应的 ...
- 导入excel2007文件问题
基于oledb方式导入excel2007文件时,使用如下链接字符串: string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Sour ...
- Foreach遍历
前天在项目中遇到一个问题,foreach遍历过程中修改responses中的对象,其中responses的类型:IEnumerable<Order>,代码如下: foreach (Orde ...
- SpringMVC问题- MultipartConfig 配置问题以及解决方式
http://www.cnblogs.com/weilu2/p/springmvc_fileupload_with_servlet_3_0.html
- CentOS 7 安装字体库 & 中文字体
前言 报表中发现有中文乱码和中文字体不整齐(重叠)的情况,首先考虑的就是操作系统是否有中文字体,在CentOS 7中发现输入命令查看字体列表是提示命令无效: 如上图可以看出,不仅没有中文字体,连字体 ...
- lua 面向对象编程类机制实现
lua no class It is a prototype based language. 在此语言中没有class关键字来创建类. 现代ES6, 已经添加class类. prototype bas ...
- 【Xpath学习】xpath都不会,说什么你做网站自动化测试的?
嗯我确实不太会.感觉我写的随笔很渣,不一定对,大家不要被我误导了,最好不要看.我也尽量保证写出来都是对的. 首先这俩给我搞晕了 1. // 不管层级: 相对路径 2. / care 层级: 表示到 ...
- Json_异常_net.sf.json.JSONException: JSONObject["solution"] not found.
net.sf.json.JSONException: JSONObject["solution"] not found. 没有这个元素造成的. 问题代码: JSONObject j ...
- DataRow映射实体
public static T ConvertToModel<T>(DataRow dr) where T : new() { T t = new T(); Type modelType ...