PHP Real Estate Google Geocoder将V2更新为V3


PHP Real Estate Google Geocoder update V2 to V3

我有以下代码(我最初没有对这个网站进行编程),但不确定它做了什么,因为每次运行它都会抛出谷歌错误610,以及为什么我们需要更新到V3,但现在它跳到了'Geocoding skipped'的else语句。这是谷歌Goecoding v2的程序,我正在尝试将其更新到v3。就像我说的是别人做的然后离开了,现在它坏了,我就是那个试图修复它的人。

$geocode = !($listing  
    && $listing->getAddress1() == $commonFieldValues['address_1'] 
    && $listing->getAddress2() == $commonFieldValues['address_2'] 
    && $listing->getCity() == $commonFieldValues['city'] 
    && $listing->getState() == $commonFieldValues['state']
    && $listing->getZipCode() == $commonFieldValues['zip_code']
);
if($geocode) {
    $baseUrl = 'http://maps.google.com/maps/geo?output=xml&key=' . OurMLS_Constants::getGoogleMapsApiKey();
    $url = $baseUrl . '&q=' . urlencode(join(', ', $listing->getAddressLines(true, true)));
    $xml = simplexml_load_file($url);
    if($xml !== false) {
        // Curious what the status codes mean see...
        // http://code.google.com/apis/maps/documentation/reference.html#GGeoStatusCode
        $status = $xml->Response->Status->code;
        if($status != '200') {
            print "Google Maps geocode request returned with status code '$status''n";
        } else {
            $coordinates = $xml->Response->Placemark->Point->coordinates;
            $coordinatesSplit = split(",", $coordinates);
            $latitude = (float) $coordinatesSplit[1];
            $longitude = (float) $coordinatesSplit[0];
            $listing->setLatitude($latitude);
            $listing->setLongitude($longitude);             
        }
    }
} else {
    print ', Geocoding skipped';
}

我已经将其更新为我认为在V3中会得到相同的结果(因为只要我们可以将Lat和long拉入数据库,网站和地图的其余部分就可以工作)(不付费触摸未损坏的东西)

$geocode = !($listing  
    && $listing->getAddress1() == $commonFieldValues['address_1'] 
    && $listing->getAddress2() == $commonFieldValues['address_2'] 
    && $listing->getCity() == $commonFieldValues['city'] 
    && $listing->getState() == $commonFieldValues['state']
    && $listing->getZipCode() == $commonFieldValues['zip_code']
);
if($geocode) {
    $baseUrl = 'http://maps.googleapis.com/maps/api/geocode/xml';
    $url = $baseUrl . "?address=" . urlencode(join(', ', $listing->getAddressLines(true, true))) . "&sensor=false" ;
    $xml = simplexml_load_file($url);
    if($xml !== false) {
        $status = $xml->GeocodeResponse->status;
        if($status != 'OK') {
            print "Google Maps geocode request returned with status code '$status''n";
        } else {
            $latitude = $xml->GeocodeResponse->geometry->location->lat;
            $longitude = $xml->GeocodeResponse->geometry->location->lng;
            $listing->setLatitude($latitude);
            $listing->setLongitude($longitude);
        }
    }
} else {
    print ', Geocoding skipped';
}

如果有任何帮助,我们将不胜感激,这是一项cron工作,可以提取RETS提要并保存到数据库,当它将信息保存到本地数据库时,它应该对数据库中的地址进行地理编码,这样当列表显示时,它们就会有一个谷歌地图。

我真的不确定"$geocode=!("做什么。这个循环会为它提取的每个地址运行,除了地理编码之外,其他一切都正常。

我不确定它为什么要提取并获取状态代码,但现在它只是跳过

这是两个xml文件http://maps.google.com/maps/geo?output=xml&q=1600%宾夕法尼亚州%20ave%20washington%20dchttp://maps.googleapis.com/maps/api/geocode/xml?address=1600%pennsylvania%20ave%20washington%20dc&传感器=错误

$geocode = !(...bunch of stuff...);说:"把这堆东西作为布尔值来计算(即true或false)。然后求反(即,如果它是true,就把它设为false;如果它是false,就把其设为true)。"查看文档,了解更多关于逻辑运算符的信息。

因此,您需要从括号中的内容开始:

$listing  // does the listing object exist?
&& $listing->getAddress1() == $commonFieldValues['address_1']   // and does "address1" equal this other thing
&& $listing->getAddress2() == $commonFieldValues['address_2']   // and does "address2" equal this other thing 
&& $listing->getCity() == $commonFieldValues['city']   // and does "city" equal this other thing
&& $listing->getState() == $commonFieldValues['state']   // you get the picture...
&& $listing->getZipCode() == $commonFieldValues['zip_code']

如果所有这些都是真的,那么$geocode将是假的(因为!运算符),并且只有在$geocode为真的情况下才会进行地理编码。

我对你的代码了解不多,但我认为这是

如果我有一个列表,但地址不匹配,城市也不匹配,州都不匹配,邮政编码又不匹配,那么我需要对其进行地理编码。

因此,看看您的$listing对象(它存在吗?)和$commonFieldValues数组(这些值是什么,它们是您期望的值吗?)。