<?php
trait Geocodable{
/** @var string */
protected $address; /** @var \Geocoder\Geocoder */
protected $geocoder; /** @var \Geocoder\Result\Geocoded */
protected $geocoderResult; public function setGeocoder(\GeoCoder\GeocoderInterface $gocoder)
{
$this->geocoder = $gocoder;
} public function setAddress($address)
{
$this->address = $address;
} public function getLatitude()
{
if (isset($this->geocoderResult) == false){
$this->geocodeAddress();
} return $this->geocoderResult->getLatitude();
} public function getLongitude()
{
if (isset($this->geocoderResult) === false){
$this->geocodeAddress();
} return $this->geocoderResult->getLongitude();
} protected function geocodeAddress()
{
$this->geocoderResult = $this->geocoder->geocode($this->address); return true;
}
} //使用性状
class RetailStore
{
use Geocodable; //这里是类的实现
} $geocoderAdapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
$geocoderProvider = new \Geocoder\Provider\GoogleMapsProvider($geocoderAdapter);
$geocoder = new \Geocoder\Geocoder($geocoderProvider); $store = new RetailStore();
$store->setAddress('420 9th Avenue, New York, NY 10001 USA');
$store->setGeocoder($gocoder); $latitude = $store->getLatitude();
$longitude = $store->getLongitude();
echo $latitude, ':', $longitude;

PHP性状的使用的更多相关文章

  1. php中trait(性状)与generator(生成器)

    PHP中trait(性状)与generator(生成器) 一.trait (性状) 最近在看Josh Lockhat的<Modern PHP>,这本书很薄.但是其中给出了一个很重要的学习方 ...

  2. Genome-wide Complex Trait Analysis(GCTA)-全基因组复杂性状分析

    GCTA(全基因组复杂性状分析)工具开发目的是针对复杂性状的全基因组关联分析,评估SNP解释的表型方差所占的比例(该网站地址:http://cnsgenomics.com/software/gcta/ ...

  3. 性状、生成器、闭包、OPcache【Modern PHP】

    目录 性状 Trait 生成器 闭包 Zend OPcache PHP发展这么多年,技术.架构都已经革新,了解现代PHP很重要,最近在看Model PHP这本书,系统的了解下PHP相关的概念. 性状 ...

  4. modern php笔记---2.1、特性(命名空间、特性、性状)

    modern php笔记---2.1.特性(命名空间.特性.性状) 一.总结 一句话总结: legend2是真的非常好用,资质起码提升5倍,也就是学习效率提升了起码5倍 1.命名空间实质? 从技术层面 ...

  5. modern php笔记---php (性状)

    modern php笔记---php (性状) 一.总结 一句话总结: trait是和继承一个层次的东西 一个类use MyTrait;后,trait中的方法覆盖父类方法,当前类中的方法覆盖trait ...

  6. 【GS文献】测序时代植物复杂性状育种之基因组选择

    综述:Genomic Selection in the Era of Next Generation Sequencing for Complex Traits in Plant Breeding 要 ...

  7. Atitit 软件工程概览attilax总结

    Atitit 软件工程概览attilax总结 1.1. .2 软件工程的发展 进一步地,结合人类发展史和计算机世界演化史来考察软件工程的发展史. 表2 软件工程过程模型 表2将软件工程的主要过程模型做 ...

  8. R语言:常用统计检验

    统计检验是将抽样结果和抽样分布相对照而作出判断的工作.主要分5个步骤: 建立假设 求抽样分布 选择显著性水平和否定域 计算检验统计量 判定 -- 百度百科 假设检验(hypothesis test)亦 ...

  9. react-echarts之折线图的显示

    react中想要实现折线图和饼图的功能,需要引入react-echarts包,然后再实现折线图的功能.我这里引用的版本是:0.1.1.其他的写法参echarts官网即可.下面详细讲解的是我在react ...

随机推荐

  1. [转]搬瓦工教程之九:通过Net-Speeder为搬瓦工提升网速

    搬瓦工教程之九:通过Net-Speeder为搬瓦工提升网速 有的同学反映自己的搬瓦工速度慢,丢包率高.这其实和你的网络服务提供商有关.据我所知一部分上海电信的同学就有这种问题.那么碰到了坑爹的网络服务 ...

  2. eclipse下的emacs风格快捷键

    Ieclipse emacs类快捷键 win + shift + b 切换设置断点 win + shift + f 格式化代码 win + shift + l 显示绑定的快捷键 win + shift ...

  3. linux 查找文件的命令

    http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html

  4. [SharePoint 2013] Subscribe report within SharePoint mode

    param([string]$path, [string]$fileName, [string]$storage) $description = "Save in $storage as $ ...

  5. Java 泛型约束

    类型约束: import java.util.List; import java.util.ArrayList; import java.util.LinkedList; /** * Created ...

  6. tomcat 格式化输出到kafka

    cat /data/tomcat/conf/server.xml <Valve className="org.apache.catalina.valves.AccessLogValve ...

  7. ora-02292

    select  table_name from all_constraints where constraint_name = '约束的名称'

  8. XPath 实例

    在本节,让我们通过实例来学习一些基础的 XPath 语法. XML实例文档 我们将在下面的例子中使用这个 XML 文档: "books.xml" : <?xml versio ...

  9. 1047: 小A的计算器

    1047: 小A的计算器 时间限制: 1 Sec  内存限制: 128 MB提交: 124  解决: 105[提交][状态][讨论版] 题目描述 以往的操作系统内部的数据表示都是二进制方式,小A新写了 ...

  10. jffs2和yaffs2文件系统制作工具的编译与使用

    一 . 先准备文件 mtd-utils-1.4.5.tar.bz2 ftp://ftp.infradead.org/pub/mtd-utils/ zlib-1.2.5.tar.bz2 http://z ...