# create a connection to the database instance on localhost. If you # have not done anything 'clever' the username 'system' will work # with the passWord that you defined at installation $conn=oci_connect('username','password', "//127.0.0.1/XE");
# Query our address table $sql = "SELECT name, address1, city, state, zip from address";
# oci_parse is part of the Oracle PHP library to parse the SQL statement $stmt = oci_parse($conn, $sql);
# oci_execute not surprisingly executes the statement we parsed in the previous line oci_execute($stmt);
# This loads the associative array $row with the values of each row in our # database in turn while ( $row = oci_fetch_assoc($stmt) ) { # print_r dumps a variable, including all of the keys for an associative array print_r($row); # assemble the query variable for our call to geocoder.us $address = $row["ADDRESS1"] . "," . $row["CITY"] . "," . $row["STATE"] . " " . $row["ZIP"]; # pull the name out of the associative array $name = $row["NAME"]; # the url to the free service of geocoder.us to return the data in CSV format $url = "http://rpc.geocoder.us/service/csv?address=" . (urlencode($address)); # open the url $w = fopen($url,"r"); #parse the CSV returned from the page into the array $result $result = fgetcsv($w,8000); fclose($w);
# query to update the address table with the lat/long we got from geocoder.us # granted it is poor database design to have sUCh an uncertain key as 'name' # be our primary key…I'll leave it as an exercise to the reader to implement # this code in a way that doesn't make DBA's cry. $sqlu = "update address set =$latitude, =$longitude where NAME='$name'"; echo "sqlu $sqlu/n"; # as before, parse the SQL statement $stmtu = oci_parse($conn, $sqlu); # and execute the statement oci_execute($stmtu); } ?>
无需帮手的三维地图
所有努力都是为了向您提供包含空间数据的数据库。现在,您可以清楚地了解客户所在的位置!利用该信息,您可以完成很多事情,例如,分析市场,计划宣传活动、销售路线以及送货路线,但首当其冲的是我们要在地图上看到这些数据。两年以前,在地图上显示数据十分困难,您必须使用昂贵且专业的工具,或使用学习起来异常困难的复杂工具。幸运的是,这一切都成为了过去。 Google Earth 是一个适用于 Windows 和 Mac 的桌面应用程序,其用途不仅限于地图,还提供了一个 3D 世界模型。在城镇数量不断增加的今日,它还包括了多个 3D 建筑物轮廓。您还可以使用 Google Sketch Up 将自己的 3D 模型添加到显示中。 Google Earth 可从 http://earth.google.com 获得。这是一个免费版本,但对于 Google Earth Plus,您每年需支付 20 美元,对于 Google Earth Pro,您每年需支付 400 美元。付费版本增加了诸如全球定位系统 (GPS) 集成之类的功能。(单击此处了解各个版本的不同之处。)网站说明非常简单,请立即下载使用吧!刚开始,您会看到一个从太空视角拍摄的地球视图。然后,可将视图放大来搜索位置、探索世界,就像 Lewis 和 Clark(当今探险军团的成员)一样。 活跃的 Google Earth 社区会发布一些空间信息文件。例如,单击此处阅读并下载有关 Lewis 和 Clark 探险之旅的 Google Earth 文件:29917-lewis_and_clark_eXPedition.kmz。您会注重到,Google Earth 文件的扩展名为 KML(即 Keyhole 标记语言,Google Earth 在以前称为 Keyhole)或 KMZ(通过 gzip 压缩的 Keyhole 标记语言)。KMZ 文件可通过 WinZip 或 Stuffit Expander 进行解压缩。 我喜欢我的 GUI,除非要尝试进行脚本编写,因此从 OSX 终端命令行,您可以输入以下命令:gunzip -S ".kmz" 29917-lewis_and_clark_expedition.kmz 打开该文件后,您将发现它只不过是一个 xml 文件。好吧,或许并不是十分简单,但易于阅读。请深入阅读 Google Earth KML 文档! 例如,以下是描述 Camp Disappointment 的地标。<Placemark> <description><![CDATA[ <a href="http://www.lewis-clark.org/content/content-article.asp?ArticleID=1069"> Click to read entry</a>]]></description> <name>17: Camp Disappointment</name> <LookAt> <longitude>-112.820632</longitude> <latitude>48.716670</latitude> <range>1000.000</range> <tilt>0</tilt> <heading>0</heading> </LookAt> <styleUrl>root://styles#khStyle929</styleUrl> <Point> <coordinates>-112.820632,48.716670,0</coordinates> </Point> </Placemark> 当您调出 Lewis and Clark 文件后,您将看到 Google Earth 是如何呈现该 Camp Disappointment 描述的。 <name> 元素以点元素的 <coordinates> 元素中指定的 X, Y, Z 坐标形式显示在地图上(经度 = X,纬度 = Y,海拔 = Z,在本例中为 0)。单击该点时,会弹出一个描述球,其中显示了名称和描述元素的内容,以及到此处去或从此点出发的选项。 请非凡注重,描述可以包含 URL。因此,假如该地标描述了您的一个客户,那么就可以在调出中包含有关该客户的其他属性,然后在您的 CRM 系统中嵌入一个指向客户页面的链接。 <styleURL> 元素包含一个指向标记该位置的“图钉”URL 的链接。在本例中,该样式包含在本地文件系统上。样式描述还可以包含在 KML 文档内或外部 URL 中。 最后,看一下 <LookAt> 元素。双击地标,您会到达 <LookAt> 元素中指定的经度和纬度,并看到由 <heading>、<tilt> 以及 <range> 元素描述的视图点。这答应您在指定视图点的地方创建地标。例如,以下是一个完整的 KML 文件,其内容为“前往旧金山的 Crissy Field 观赏金门大桥”:<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.0"> <Placemark> <name>crissy field</name> <LookAt> <longitude>-122.4592370657115</longitude> <latitude>37.8050682478946</latitude> <altitude>0</altitude> <range>1000.275193579794</range> <tilt>90</tilt> <heading>315</heading> </LookAt> <styleUrl>root://styles#default</styleUrl> <Point> <coordinates>-122.4592370657115,37.8050682478946,0</coordinates> </Point> </Placemark> </kml> 为了简单起见,您可以除去其中一些属性。以下是这两个明确地点的最简单、有用的 KML 描述: <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.0"> <Folder> <Placemark> <name>First Place</name> <Point> <coordinates>-122.5,37.8,0</coordinates> </Point> </Placemark> <Placemark> <name>Random Place</name> <Point> <coordinates>-122.6,37.9,0</coordinates> </Point> </Placemark> </Folder> </kml> 以下是抓取地理编码地址并生成 KML 文件的 PHP 程序:<?PHP
$conn=oci_connect('username','password', "//127.0.0.1/XE"); $sql = "SELECT name, address1, city, state, zip, latitude, longitude from address a"; $stmt = oci_parse($conn, $sql); oci_execute($stmt);