Results 1 to 2 of 2

Thread: OR map polygon search addOn

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Default OR map polygon search addOn

    Hello!

    I am new to OR and addon creating. But now I am creating map polygon search addon. I have working code. I generate page by function and use google maps.

    Could you take a look and suggest how to improve it?
    Now it provides a search not in the polygon but just in the rectangular area. How to make it search only in the polygon bounds?

    Here are main functions I use (I skipped sqls for getting coordinates)

    PHP Code:
    // This function returns us listing IDs in the rectangular area
    function VitalikAddOn_map_bounds($min_lat,$max_lat,$min_long,$max_long){
        global 
    $conn$config;
        
    $tempID '';
        
    $itemlist = array();

    if (!isset(
    $max_lat) or !isset($min_lat) or !isset($max_long) or !isset($min_long))
        {
            
    $max_lat    =    '25.79719162496379';
            
    $max_long    =    '-80.20737148132321';
            
    $min_lat    =    '25.778952894879826';
            
    $min_long    =    '-80.24230457153317';
        };

        require_once(
    $config['basepath'] . '/include/misc.inc.php');
        
    $misc = new misc();
        
    $listing_id $misc->make_db_extra_safe($min_lat);
        
    $sql 'SELECT `listingsdb_id` FROM `listings_long_lat` WHERE `latitude`>'.$min_lat.' and `latitude`<'.$max_lat.' and `longitude`>'.$min_long.' and `longitude`<'.$max_long;
        
    $recordSet $conn->Execute($sql);
        if (!
    $recordSet) {
            
    $misc->log_error($sql);
            }
        while (!
    $recordSet->EOF) {
        
    $tempID $misc->make_db_unsafe($recordSet->fields['listingsdb_id']);
        
    $item['itemid'] = $tempID;
        
    $item['address'] = VitalikAddOn_listing_street_name($tempID).' '.VitalikAddOn_listing_street_num($tempID);
        
    $item['city'] = VitalikAddOn_listing_city($tempID);
        
    $item['state'] = VitalikAddOn_listing_state($tempID);
        
    $item['zip'] = VitalikAddOn_listing_zip($tempID);
        
    $item['lat'] = VitalikAddOn_listing_lat($tempID);
        
    $item['lng'] = VitalikAddOn_listing_long($tempID);
        
    $item['title'] = get_title($tempID);
        
    $item['thumb'] = VitalikAddOn_listing_thumb($tempID);
        
    $item['price'] = VitalikAddOn_listing_price($tempID);


        
    array_push(    $itemlist $item);
        
    $recordSet->MoveNext();
        }

        
    $itemJSON json_encode($itemlist);
        
    $display $itemJSON;
        return 
    $display;

    PHP Code:
    // This function generates the search page with map
    function VitalikAddOn_map($listing_id) {
        global 
    $conn$config$jscript;
        require_once(
    $config['basepath'] . '/include/core.inc.php');
        
    $page = new page_user();
        
    $page->load_page($config['basepath'] . '/addons/VitalikAddOn/map_inside/index.php');
        
        
    $jscript .= "<script type=\"text/javascript\">\r\n";
        
    $jscript .= "<!--\r\n";

    $jscript .= "
        //main map  function
        $(loadgeoSearchMap);

        var geoSearchMap;
        var poly;
        var count = 0;
        var points = new Array();
        var markers = new Array();
        var listingMarkers = new Array();
        var lineColor = \"#0000af\";
        var fillColor = \"#335599\";
        var lineWeight = 3;
        var lineOpacity = .8;
        var fillOpacity = .2;
        var searchPage = 0;
        
        var mark;
        var geocoder;

        function findUser()
        {
            jQuery('#cityText').val(geoip_city());
            jQuery('#stateText').val(geoip_region());
            jQuery('#zipText').val(geoip_postal_code());
            jQuery('#countryText').val(geoip_country_name());
        }

        function searchbtn()
        {
            newSearch();
        }
        
    /*        
            geocoder = new google.maps.Geocoder();
        
            var apiKey = \"ABQIAAAA4CrElVtUACfr1Yv2GaSBMBSaquASLSEoIQsidDv7Wk-wlXSOLxQVzVszw8as0gkpDxbsuoHk_ZjwRw\";
            var street = jQuery('#addyText').val();
            var city = jQuery('#cityText').val();
            var state = jQuery('#stateText').val();
            var zip = jQuery('#zipText').val();
            //var country = 'usa';
            var country = geoip_country_name();
            var address = street + ' ' + city + ' ' + state + ' ' + zip;
            geocoder.geocode( { 'address': address}, function(results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                geoSearchMap.setCenter(results[0].geometry.location);
                radiusCenter = geoSearchMap.getCenter();
                doDrawCircle();            
              } else {
                alert(\"Geocode was not successful for the following reason: \" + status);
              }
            });
    */
        
        function loadgeoSearchMap()
        {
            //3.0 api
            var myLatlng = new google.maps.LatLng(25.77717, -80.176849);
            var myOptions = {
              zoom: 13,
              center: myLatlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
            };
            geoSearchMap = new google.maps.Map(document.getElementById(\"geoSearchOver\"),myOptions);
            google.maps.event.addListener(geoSearchMap, 'click', leftClick);
        }
        
        function leftClick(mouseEvent)
        {
            if(mouseEvent)
            {
            
                count++;
        
            var sz = new google.maps.Size(12, 20);        
            var markerOptions = {
                flat: true,
                position: mouseEvent.latLng,
                draggable: true,
                visible: true
                };
            //don't make this global
            var polyMarker = new google.maps.Marker(markerOptions);
            markers.push(polyMarker);
            polyMarker.setMap(geoSearchMap);

        
            /* Drag listener*/
            google.maps.event.addListener(polyMarker, 'drag', function() {
            drawOverlay();
            });
            
            /* Second click listener*/
            google.maps.event.addListener(polyMarker, 'click', function() {        
            /* Find out which marker to remove*/
            for(var n = 0; n < markers.length; n++) {
             if(markers[n] == polyMarker) {
              markers[n].setMap(null);
              break;
             }
            }
            
            /* Shorten array of markers and adjust counter*/
            markers.splice(n, 1);
            if(markers.length == 0) {
              count = 0;
            }
             else {
              count = markers[markers.length-1].content;
              drawOverlay();          
            }
            });
            drawOverlay();            
            }
        }

        function drawOverlay()
        {    
            if(poly)
            {
                poly.setMap(null);
            }
            points.length = 0;
            
            for(i = 0; i < markers.length; i++)
            {
              points.push(markers[i].getPosition());
            }
            
            points.push(markers[0].getPosition());
            var polyOptions = {
                paths: points,
                strokeColor: '#0000af',
                fillColor: '#335599',
                fillOpacity: 0.25,
                strokeWeight: 1
            };
            poly = new google.maps.Polygon(polyOptions);    
            poly.setMap(geoSearchMap);
        }    

        function clearMap()
        {    
            //geoSearchMap.clearOverlays();
            if(poly)
                poly.setMap(null);
            for(var n = 0; n < listingMarkers.length; n++) {
              listingMarkers[n].setMap(null);
            }        
            for(var n = 0; n < markers.length; n++) {        
              markers[n].setMap(null);
            }        
            points.length = 0;
            markers.length = 0;
            count = 0;
            jQuery('#resultsDiv').hide('slow',function(){
                jQuery('#resultsDiv').html('');
            });
            jQuery('#statusMsg').html('');
            
        }

        function newSearch()
        {
            //remove old listings
            for(var n = 0; n < listingMarkers.length; n++) {
              listingMarkers[n].setMap(null);
            }

            var statusDiv = jQuery('#statusMsg');
            statusDiv.html('<img src=\"http://www.miamirentalauthority.com/addons/VitalikAddOn/wait.gif\" alt=\"*\"> <span style=\"color:red;\">Searching...</span>');
            jQuery('#resultsDiv').hide(\"slow\");                

            var latitudes = new Array();
            var longitudes = new Array();
            var latmin;
            var latmax;
            var lngmin;
            var lngmax;
            var url = 'index.php?action=addon_VitalikAddOn_map_bounds&popup=blank';
            //var url = 'addons/VitalikAddOn/search.php';
            var html;
            var mapids = new Array();
            var statMsg;
            var compLink;
            
            for(var m = 0; m < points.length-1; m++) {
                latitudes.push(points[m].lat());
                longitudes.push(points[m].lng());
            }    
            
            latmin = latitudes[0];
            latmax = latitudes[0];
            for(var a = 1; a < latitudes.length; a++) {
                if (latitudes[a]>latmax){latmax=latitudes[a];}
                if (latitudes[a]<latmin){latmin=latitudes[a];}
            }

            lngmin = longitudes[0];
            lngmax = longitudes[0];
            for(var a = 1; a < longitudes.length; a++) {
                if (longitudes[a]>lngmax){lngmax=longitudes[a];}
                if (longitudes[a]<lngmin){lngmin=longitudes[a];}
            }

            jQuery.post(url, {min_lat:latmin, max_lat:latmax, min_long:lngmin, max_long:lngmax}, function(data){
                if(data.length > 0)
                    {
                        statMsg = '<span style=\"color:red\">' + data.length + ' listings found.</span>';
                        statusDiv.html(statMsg);
                    }else{
                        var statusMsg = 'No Listings Found In This Area';
                        statusDiv.html(statusMsg);
                    }
                        
                jQuery.each(data, function(i,item){                           
                    /*
                    item.address;
                    item.city;
                    item.state;
                    item.zip;
                    item.itemid;
                    item.lat;
                    item.lng;
                    item.title;
                    item.thumb;
                    item.price;
                    */
                                    
                    html = '';
                   
                    compLink = '/index.php?action=listingview&listingID=' + item.itemid; 
                    html += '<div style=\"float:left;margin:5px;\"><a href=\"' + compLink + '\">' + item.title + '</a>';
                    html += '<br/>' + item.address + '<br/>' + item.city + ', ' + item.state + ' ' + item.zip;
                    html += '<br/>Price: $' + item.price;
                    html += '<br/></div>';
                    html += '<div style=\"float:right;\"><img src=\" ' + item.thumb + ' \"/></div>';

                    mapids.push(item.itemid);

                    var markerPoint = new google.maps.LatLng(item.lat,item.lng);
                    createMarkers( markerPoint, html);

                });

                var uri = 'index.php?action=addon_VitalikAddOn_map_resultbox&popup=blank';
                jQuery.ajax({
                    url: uri,
                    type: 'POST',
                    data: {'listingID':mapids},
                    success: function(data) {
                        jQuery('#resultsDiv').html(\"\");
                        jQuery('#resultsDiv').append(data);
                        jQuery('#resultsDiv').show('slow');
                    }
                });

            },\"json\");

        }
        
        
        function createMarkers(point, html)
        {
            var sz = new google.maps.Size(28, 24);
            //var origin = new google.maps.Point(point.lat(), point.lng());
            var markerOptions = {
                flat: true,
                position: point
                };
            mark = new google.maps.Marker(markerOptions);

            attachMessage(mark, html);

            listingMarkers.push(mark);
            mark.setMap(geoSearchMap);
        }

        function attachMessage(mark, html) {
            var infowindow = new google.maps.InfoWindow({
                content: '<div>'+html+'</div>'
            });
            google.maps.event.addListener(mark, 'click', function() {
            infowindow.open(geoSearchMap,mark);
            });
        }
        
        "
    ;

        
    $jscript .= "//-->\r\n";
        
    $jscript .= "</script>\r\n";

        return 
    $page->page;


  2. #2
    the_sandking's Avatar
    the_sandking is offline hadron remnant - Moderation Fachmann
    Join Date
    Apr 2003
    Location
    Nullspace
    Posts
    5,289

    Default Re: OR map polygon search addOn

    THREAD MOVED - to OR v3 add-on Help and Discussion. The add-on Hooks and API forum area is for asking specific questions about your code.
    "Much of what looks like rudeness in hacker circles is not intended to give offense. Rather, it's the product of the direct, cut-through-the-BS communications style that is natural to people who are more concerned about solving problems than making others feel warm and fuzzy."

    "We gotta' go to the crappy town where I'm a hero!"
    -Hoban 'Wash' Washburne 2485-2519


    "When you’re born you get a ticket to the freak show. When you’re born in America, you get a front-row seat.."
    -George Carlin 1937-2008

    New to Open-Realty® and need help? Check the:
    -OR DOCUMENTATION -

    Important: Read this at least once in your lifetime
    How To Ask Questions The Smart Way

Similar Threads

  1. Polygon Map Search Option
    By gil in forum General Help (CLOSED)
    Replies: 2
    Last Post: 10-09-2009, 07:17 PM
  2. 2 keywords search addon
    By serdas in forum Work
    Replies: 0
    Last Post: 08-07-2009, 02:43 PM
  3. agent search addon
    By serdas in forum Addon help, ideas and discussion (CLOSED)
    Replies: 2
    Last Post: 03-17-2009, 10:17 PM
  4. Help w/new search addon
    By tmeyer45458 in forum Addon help, ideas and discussion (CLOSED)
    Replies: 7
    Last Post: 11-05-2008, 04:00 PM
  5. Addon - for search results
    By halifax in forum Addon help, ideas and discussion (CLOSED)
    Replies: 4
    Last Post: 10-04-2006, 08:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •