Jump to content

Display Listings Based On Users Ip


nicholas

Recommended Posts

This thread shows a way to take the ip address from a listing and show related listings within x miles.

 

http://www.reviewsforjoomla.com/forum/index.php?topic=17858.msg74898#msg74898

 

<h2>List Places Nearby</h2>
<?php
$lat_field = 'jr_latitude';
$lon_field = 'jr_longitude';
$center = array(
   $CustomFields->field($lat_field,$listing,false,false),
   $CustomFields->field($lon_field,$listing,false,false),
);
$radius = 100; // Miles or Km. You have to change the degree distance below accordingly
$degreeDistance = 40076/360; // For Km use 40076/360;

$lat_range = $radius/$degreeDistance; 
$lon_range = $radius/abs(cos($center['lat']*pi()/180)*$degreeDistance); 

$min_lat = $center['lat'] - $lat_range;
$max_lat = $center['lat'] + $lat_range;
$min_lon = $center['lon'] - $lon_range;
$max_lon = $center['lon'] + $lon_range;
$squareArea = "(Field.$lat_field BETWEEN $min_lat AND $max_lat AND Field.$lon_field BETWEEN $min_lon AND $max_lon)";
$moduleParams = array(
    'module_id'=>rand(1000,10000),
    'module'=>array(
    'listing_order'=>'latest', // rdate|rating|rrating|topratededitor|raviews|random|featuredrandom|rhits
    'summary'=>'0',
    'summary_words'=>'10',
    'tmpl_suffix'=>'', // Theme file suffix. The default theme used is /modules/listings.thtml
    'tn_show'=>'1',
    'tn_width'=>'50',
    'tn_mode'=>'crop', // crop|scale
    'extension'=>'com_content',
    'cat_auto'=>'0',
    'dir'=>'2',
    'category'=>'',
    'listing'=>'',
'custom_where'=>$squareArea,
    'custom_order'=>'',    
    'nav_position'=>'bottom', // bottom|side
    'orientation'=>'horizontal', // horizontal|vertical
    'slideshow'=>'0',
    'slideshow_interval'=>'6', // number of seconds
    'module_total'=>'10', // Max. number of results
    'module_limit'=>'4', // Results per page
    'columns'=>'2',
    'show_numbers'=>'0',    
    'filter_listing_period'=>'', // Filter: Listings submitted in past x days
    'filter_review_period'=>'', // Filter: Listings with reviews submitted in past x days
    'filter_review_count'=>'', // Filter: Listings with review count higher than
    'filter_avg_rating'=>'', // Filter: Listings with average rating higher than
    'moduleclass_sfx' => '' // Module suffix
    )
);
echo $this->requestAction('module_listings/index/',$moduleParams);        
?>	

 

Google service easily locates someones geo locale based on their ip address (im not sure if this is what jreviews already does to use the geomap part)

 

https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding

 

Now what im hoping is with those 2 maybe someone can figure out a way to combine the 2.  So it will just take the long lat values given and post them into the $lat_field = 'jr_latitude'; $lon_field = 'jr_longitude'; fields.

 

Or another way if this seems too hard.  It seems like an easy setup but im not good enough yes with this style of coding to do it :(

Link to comment
×
×
  • Create New...