Changeset 7083

Show
Ignore:
Timestamp:
11/26/08 01:44:04 (6 weeks ago)
Author:
daybreaker
Message:

refs #1131:

  • 스크립트 실행시간 제한에 따라, 한 번에 캐시로 다 넣지 않고 요청이 들어올 때마다 일정 개수씩 넣도록 함
Location:
trunk/plugins/GoogleMap
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/GoogleMap/gmap_common.js

    r7082 r7083  
    7878function GMap_findLocationCallback(response, gmap, location_info, title, link, boundary, locations) { 
    7979    if (!response || response.Status.code != 200) { 
    80         // alert('Can\'t retrieve this address "'+address+'"'); 
     80        if (process_count != undefined) 
     81            process_count++; 
    8182    } else { 
    8283        var place = response.Placemark[0]; 
  • trunk/plugins/GoogleMap/index.php

    r7082 r7083  
    137137            locationMap.enableContinuousZoom(); 
    138138            locationMap.setCenter(new GLatLng(<?php echo $lat;?>, <?php echo $lng;?>), <?php echo $zoom;?>); 
    139             boundary = new GLatLngBounds(locationMap.getCenter()); //, new GLatLng(<?php echo $lat+0.1;?>, <?php echo $lng+0.1;?>)); 
     139            boundary = new GLatLngBounds(locationMap.getCenter()); 
    140140            var locations = new Array(); 
    141141<?php 
    142142    $count = 0; 
     143    $countRemoteQuery = 0; 
    143144    foreach ($locatives as $locative) { 
    144145        $locative['link'] = "$blogURL/" . ($blog['useSloganOnPost'] ? 'entry/' . URL::encode($locative['slogan'],$service['useEncodedURL']) : $locative['id']); 
    145146        $row = POD::queryRow("SELECT * FROM {$database['prefix']}GMapLocations WHERE blogid = ".getBlogId()." AND address = '".POD::escapeString($locative['location'])."'"); 
    146         $found = false; 
     147        $result = 9; // 0 = found, 1 = find in client, 9 = not found 
    147148        if ($row == null || empty($row)) { 
    148             //echo "\t\t\t/* New location query */\n"; 
    149149            // Recursively repeat until location is found. (continuously reducing accuracy) 
    150150            $addr = explode(' ', _GMap_normalizeAddress($locative['location'])); 
    151151            while (true) { 
     152                if ($countRemoteQuery == 12) { // not to exceed script-running time limit 
     153                    $result = 1; 
     154                    break; 
     155                } 
    152156                $url = "http://maps.google.co.kr/maps/geo?q=".urlencode(trim(implode(' ', $addr)))."&output=csv&sensor=false&key={$config['apiKey']}"; 
    153                 //echo "\t\t\t/* recurse : $addr */\n"; 
    154157                $response = requestHttp('get', $url, false, 'text/plain'); 
     158                $countRemoteQuery++; 
    155159                if ($response === false) { 
    156                     $found = false; 
     160                    $result = 9; 
    157161                    break; 
    158162                } else { 
     
    161165                    if ($response_csv[0] == '200') { 
    162166                        // Insert for later use. 
    163                         //echo "\t\t\t/* read from api, {$locative['location']} */\n"; 
    164167                        $lat = $response_csv[2]; 
    165168                        $lng = $response_csv[3]; 
    166169                        POD::execute("INSERT INTO {$database['prefix']}GMapLocations VALUES (".getBlogId().", '".POD::escapeString($locative['location'])."', $lng, $lat, NOW())"); 
    167                         $found = true; 
     170                        $result = 0; 
    168171                        break; 
    169172                    } else { 
    170                         //echo "\t\t\t/* can't retrieve result for {$locative['location']} */\n"; 
    171173                        $lat = null; $lng = null; 
    172                         $found = false; 
     174                        $result = 9; 
    173175                        if (count($addr) == 1) 
    174176                            break; 
    175                         if (!$found) 
     177                        if ($result == 9) 
    176178                            array_pop($addr); 
    177179                        continue; 
     
    179181                } 
    180182            } 
    181             if (!$found) { 
    182                 // Not found. 
    183                 //echo "\t\t\t/* no result for {$locative['location']} */\n"; 
     183            if ($result == 9) { 
     184                // Not found. Don't try also later. 
    184185                POD::execute("INSERT INTO {$database['prefix']}GMapLocations VALUES (".getBlogId().", '".POD::escapeString($locative['location'])."', NULL, NULL, NOW())"); 
    185186            } 
    186187        } else { 
    187             //echo "\t\t\t/* read from db : {$locative['location']} */\n"; 
    188188            $lat = $row['latitude']; 
    189189            $lng = $row['longitude']; 
    190             $found = true; 
    191         } 
    192         if ($found && !is_null($lat)) { 
     190            $result = 0; 
     191        } 
     192        switch ($result) { 
     193        case 0: // found 
    193194            echo "\t\t\tGMap_addLocationMarkDirect(locationMap, {address:GMap_normalizeAddress('{$locative['location']}'), path:'{$locative['location']}'}, '".str_replace("'", "\\'", $locative['title'])."', encodeURI('".str_replace("'", "\\'", $locative['link'])."'), new GLatLng($lat, $lng), boundary, locations);\n"; 
    194         } else 
     195            break; 
     196        case 1: // find in client 
     197            echo "\t\t\tGMap_addLocationMark(locationMap, {address:GMap_normalizeAddress('{$locative['location']}'), path:'{$locative['location']}'}, '".str_replace("'", "\\'", $locative['title'])."', encodeURI('".str_replace("'", "\\'", $locative['link'])."'), boundary, locations);\n"; 
     198            break; 
     199        case 9: 
    195200            echo "\t\t\tif (process_count != undefined) process_count++;\n"; 
     201        } 
    196202        $count++; 
    197203    } 
    198204?> 
    199             //window.setTimeout('locationFetchPoller(<?php echo $count;?>);', polling_interval); 
    200             adjustToBoundary(); 
     205            window.setTimeout('locationFetchPoller(<?php echo $count;?>);', polling_interval); 
     206            //adjustToBoundary(); 
    201207        } else { 
    202208            c.innerHTML = '<p style="text-align:center; color:#c99;">이 웹브라우저는 구글맵과 호환되지 않습니다.</p>';