Closed (fixed)
Project:
Smart IP
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Oct 2010 at 19:35 UTC
Updated:
1 Jul 2012 at 11:46 UTC
Hi
First, thx for this module...
Second, i new to drupal and this might be a noob question, but here it comes:
Is it possible to use data from Smart Ip inside views? - i'm trying use the zip and country in the gmaps tool, so the map is opened in the area where the user is located - like on ex. gpsies.com.
thx
//Brian
Comments
Comment #1
arpeggio commentedHi,
Yes, you can use data from Smart IP in your views, blocks, custom module, etc. via PHP code. If you wish to access geolocation of the authenticated user, you may use Drupal $user object:
And if you wish to track including your anonymous users, enable the Device Geolocation sub module and you may access a more detailed geolocation of your visitors:
Comment #2
uolevi commentedI can access smartip from own pages with PHP and draw a separate Gmap with Smartip info:
But I don't understand if I should put the location info to Gmap's macro or where in Views.
Is there any example how to access Smartip location information from Views, because I can not find any info about Device Geolocation or Smartip information in Views, even if they are enabled.
Comment #3
arpeggio commentedI'm sorry, thought that the "Global: Custom text" have PHP input filter and can insert PHP snippet inside the Views fields but unfortunately it is not supported. I'll mark this issue as active and in the next couple of weeks I will try to start support Views.
Comment #4
socialnicheguru commentedviews customfield might work :)
Comment #5
imDhaval commentedlove to sub
Comment #6
arpeggio commented@SocialNicheGuru thank you for sharing us about views customfield. I'll try this module if find a time.
Comment #7
TNmoxa commentedI have a problem calling smart_ip_get_location() from my custom module
Fatal error: Call to undefined function smart_ip_get_location()
I'm using drupal 7.0 and Smart IP version 7.x-1.4-alpha1
Checkbox "Anonymous user" in "Roles To Geolocate" is selected.
I tried to use $_SESSION['smart_ip']['location'], but for anonymous users who come to my site first time drupal troughs a notice
Notice: Undefined variable: _SESSION in bg_picture_get_date() (line 23 of /home/content/06/7198206/html/sites/all/modules/bg_picture/bg_picture.module).
I'm new to drupal, so please help me with any solution.
Thank you!
Comment #8
arpeggio commentedComment #7 Duplicate at Undefined variable: _SESSION in smart_ip_set_session_data().
Comment #9
aworters commentedHi Arpeggio,
I am also looking to incorporate the Smart IP data into Views... I have installed the Views Custom Field module to help me but still no idea on how to use the correct PHP syntax to make the data appear in Views... Please can you lay out the correct codie for a total programming newbie?
Many thanks in advance!
Comment #10
arpeggio commentedHi aworters,
If you want to show just the visitor's coordinates:
Or if you want to display entire location data:
Or simply (if Device Geolocation module is enabled):
Comment #11
aworters commentedHi Arpeggio,
Thanks for the prompt reply with lots to work with... I am looking to output the user's County Code, City, Postal Code and the Route. The final plan is that the site would identify the User's Country and City and then display content related to their location. The initial code I have used is:
Country Code:
print $_SESSION['smart_ip']['location']['country_code'];City:
print $_SESSION['smart_ip']['location']['city'];Postal Code:
print $_SESSION['smart_ip']['location']['postal_code'];Route:
print $_SESSION['smart_ip']['location']['route'];I see the output in the preview but when I look at the Views created page it doesn't show anything.
Please excuse my total stupidity but any help making this work would be very much appreciated.
Thanks.
Comment #12
arpeggio commentedHi Aworters,
Please try to add any field (Eg. Node: Title) together with your customfield PHP code. I think Views must query something, it will not display anything if its query is empty, even if your customfield do have values.
Comment #13
aworters commentedHello again Arpeggio.. that worked well, thank you for the help. Would you be interested in doing a bit of development work to help me integrate the user's location into the content? If so, please get in touch and I will forward the project spec.
Comment #14
arpeggio commentedHi Aworters,
You're welcome! I have sent you message in your contact form.
Comment #15
socialnicheguru commentedis there a way for me to print the longitude and latitude as a decimal value?
Comment #16
arpeggio commented@SocialNicheGuru, the coordinates is already printing in decimal degrees format. Or do you mean you need to display it in Degrees, Minutes, Seconds Format? I suggest to use this code:
Comment #17
favosys commentedHello
Does anybody know how I can center the map on the current user?
I have restaurant locations and I want my users to see nearby restaurants. I have my view with all my nodes and they appear on the map all good. I know I can access the current user long a lat with PHP but I can't put PHP on the Gmap macro in the center option not in views or the Gmap configuration.
HELP !!
Comment #18
favosys commentedI also found this code to make the map from scratch which works great:
But I don't know how to add my node locations to it
So now I have a map with all my nodes but not centered on the user and a map centered on the user with no nodes.
Comment #19
socialnicheguru commentedadd location proximity to your argument for your node view.
under default value select php
add your code
I haven't tried it. You would have to check what the return values are for the location module argument but in theory it should work
Comment #20
favosys commentedThank you for a quick answer.
I tried this but I couldn't get it to work.
Coordinate type says this:
Coordinate Type:
Type of center point.
Postal code argument format: country_postcode_distance or postcode_distance
Lat/Lon argument format: lat,lon_distance
So for the PHP code I tried:
But now the map just doesn't appear
Comment #21
favosys commentedNevermind, I checked the GMAP Advanced help and I got it to work with just PHP code :)
Comment #22
socialnicheguru commentedwhere there any modifications to the above to get it to work? If so, can you share your steps?
Comment #23
kenwen commentedHi,
I'm trying to pass the current user long / lat through to a view where I sort data by distance
I've got smart ip and device geolocation modules active and from my limited understanding I should be able to pull the data from device geolocation and pass through to the views sorting criteria?
would appreciate any help!
I think this is the bit I need to do :)
Enter PHP code that returns a latitude/longitude. Do not use
. You must return only an array with float values set for the 'latitude' and 'longitude' keys.Thanks,
Ken
Comment #24
arpeggio commentedI suggest to use this:
array('latitude' => $_SESSION['smart_ip']['latitude'], 'longitude' => $_SESSION['smart_ip']['longitude'])
Note: The $_SESSION['smart_ip']['latitude'], $_SESSION['smart_ip']['longitude'] are the estimate location of your current visitor and it is already in decimal degrees.
Comment #25
birdsnbees commentedSubscribing.
Comment #26
kenwen commentedHi Arpeggio,
thanks for that!
however its not quite working - you can see it here, http://www.fitness.io/fitness-map
I'm going to try creating a location view, the one above uses nodes
thx,
Ken
Comment #27
apmsooner commented@arpeggio, made slight modifications to what you suggested to get this to work. I wanted to filter nodes by proximity to the user based on their ip address and this is what i did to achieve that because i think a few people are trying to achieve this...
add this filter- Location: Distance / Proximity
with this setting - use php code to determine latitude/longitude
the code:
The type operator produced the same result for me so didn't seem to matter. Anyhow, after much trial and error... it works for me! I assume this way is in fact correct way or anything you would revise?
Comment #28
arpeggio commentedI haven't tried this yet but thank you for sharing apmsooner. =)
Comment #29
apmsooner commentedyou bet! and thanks for the great module. It was quite easy to setup and utilize for localized ad banners which is what i've been looking to for a while now.
Comment #30
kenwen commentedwoo hoo - works for me!
exactly what i've been after, thanks
Comment #31
grasmash commentedhas this been committed?
Comment #32
apmsooner commentedAs far as what i submitted in post #27, theres no patch necessary. Its just a matter of setting up the view correctly. It works perfectly for me. I'm sure something similar can be done to display on GMAP or whatever so not sure there is anything else to do on this.
Comment #33
arpeggio commentedYes there's no need to commit/push. Thanks to apmsooner.
Comment #34
Sinan Erdem commentedHi, I think I have a similar issue:
I have nodes with some postcodes. For example a node has postcodes through 1000 - 2000. I need to show the related node to the user in a block. I can already do a search for zipcodes with views exposed filters. But what I need is to show the related node to the user from his/her IP.
Is it possible with some kind of argument or something?
Thank you very much...
Comment #35
apmsooner commentedRead #27
Comment #36
Sinan Erdem commentedapmsooner, thank you for the answer. But I really dont have the coordinate info in my nodes and I cannot geocode it, because my nodes contain an interval of zipcodes.
For example node "A" has start postcode:1000, end postcode: 1200. So if the user resides in zipcode 1111, i need to show the node A to this user.
Maybe I can write an argument php code similar to #27. I would check if the obtained postcode from smart_ip module resides in the interval. If it does, I could send a positive return. I have to try and see..
Again thanks...
Comment #37
apmsooner commentedAhh, yeah i'd say maybe look at #1 and combine what you need from there with the sample i posted in #27 and that would probably get you what you need.
Comment #38
radoya commentedEverything sounds perfect but I am not sure where is settings where I can set "use php code to determine latitude/longitude" as mentioned in post #27. When I set filter "Location: Distance / Proximity" there is no option to use any php. I tried also to set argument but under location there are only 3 option: country, region and city: no long/lat available.
I'll be very appreciate for any advice :D.
Comment #39
radoya commentedI didn't upgrade to the latest version of location module. Now all settings show up.
Thanks, anyway.
Comment #40
andrea.cavattoni commentedHere is not working:-(
the map disappear, anybody had the same problem?
Comment #41
arpeggio commentedI have implemented this feature. Please use version 6.x-1.3. Thanks to @nyleve101 for sponsoring this feature.
@cavax please create separate issue for the problem you have encountered. Thanks.