How do I set a custom location for requests? - google-assistant-sdk

How can I set the location for all requests to, for example, New York? So, if a user asks for the weather without specifying the location, it'll default to New York.

It´s not that clear but I figure out that you must refer to the source for weather info (maybe an API) by previously checking if user has it´s location shared and then get from the source using the default location.
It looks like more a coding solution than a functionality for the Google Assistant.
Something like:
const LOCATION = user.location || 'New York';
requestMyAPI(LOCATION);

Related

Rails 4 - How would I automatically detect a user's location and display it on the web app?

I currently have a working app and I would like to have Rails detect a visitor's location by the IP address and display the city and state on the homepage of my website. For example, it would display "Hello {Name} from City, State".
Visitors do not have to enter anything. I'm aware of things like GeoIP and Geocode. As far as I know about them, they are used to search for locations from IP or vice versa but they require manually inputting the info.
I need it to do it automatically as soon as the user visits my homepage. I have a Post Controller and a home page, and I just want to add some code to my home page's HAML to display the info. I plan to categorize user's posts based on location, which will be automatically filled in (I currently have a location field that user's must enter manually). If you can show me how to do that too, that would be great.
For a live example of what I'm needing, visit weather.com and you'll see your city (and the weather) on the homepage.
Additional info: I'm fairly new to Rails 4 (started 2 weeks ago) so please show me the simplest way and point me to video resources if possible.
Add to the gemfile
gem 'geocoder'
run bundle install and restart your server
Put <%= request.location.city %> in the view you want the city name to appear in.
There are lots of services that provide RESTful JSON APIs which will give you location data based on the IP address, for example: http://www.telize.com/
All you need to do is in your controller, catch the source of the HTTP request (Rack::Request) via request.env['REMOTE_ADDR'] and feed to the Geo API.
One more solution is to use ruby gem for Yandex locator (https://tech.yandex.ru/locator/). Yandex locator is a service that finds mobile devices in a region delineated by a circle. The service returns longitude, latitude and precision. https://github.com/sergey-chechaev/yandex_locator
client = YandexLocator::Client.new(api_key: 'api key', version: '1.0')
result = client.lookup(ip: { address_v4: '178.247.233.3' })
result.position
# => {"altitude"=>0.0, "altitude_precision"=>30.0, "latitude"=>41.00892639160156, "longitude"=>28.96711158752441, "precision"=>100000.0, "type"=>"ip"}

Set the Visitor ID in Adobe Analytics through DTM

I'm trying to set the Visitor ID in Adobe Analytics through DTM.
Above the s_code I have:
var visitor = new Visitor("xxxx")
visitor.trackingServer = "xxx.xx.xx.omtrdc.net"
I've created a data element where the legacy code used to call the
Visitor.getInstance("xxxx");
and set the Visitor ID to %Visitor ID%
That's not working however, and my visitor ID is always just set to %Visitor ID% and obviously not reading any values. I'd really appreciate any input that someone can give me.
Thanks,
Mike
The Visitor ID pops s.visitorID and is in general related to visitor id, but is not the same as s.visitor which is what gets popped for the VisitorAPI integration. DTM does not currently have a built-in field for the s.visitor variable, so you will have to set it yourself within the config, either in the Library Management code editor (assuming you are opting to c/p the core lib and not the "Managed by Adobe" option) or else in the Custom Page Code section.
Since you are popping it in a data layer first, you can reference the data layer like this:
s.visitor = _satellite.getVar('Visitor ID');
NOTE: A separate potential issue you may have is with whether or not the Visitor object is available for your data element. Since data elements are the first thing to be evaluated by DTM, you will need to ensure that the VisitorAPI.js library is output before your top page DTM script include.
If this is a problem for you, or if you are wanting to host VisitorAPI.js within DTM, then you may need to adjust where you are popping that stuff. For example, place the VisitorAPI core code above the custom code as the first stuff within the data element, before:
var visitor = new Visitor("xxxx") visitor.trackingServer = "xxx.xx.xx.omtrdc.net
Or, don't use the data element at all. Instead, put the VisitorAPI code within the Adobe Analytics custom code or core lib section and pop all that stuff (aboove the s.visitor assignment). Or a number of other methods; point is, VisitorAPI stuff must be loaded before the data element can make use of it, same as it must be loaded before Adobe Analytics can make use of it.
So DTM is changing pretty fast and furious right now. They have a "Marketing Cloud Service ID" that works well. Before I used that, however, I did find a way to fix the code. Crayon Violent was right, as usual, that the problem was that the script wasn't available yet. I fixed this by putting the following code in between the VisitorAPI.js and the AppMeasurement stuff in the DTM managed library.
var aA = new AppMeasurement();
aA.visitorNamespace="companyname";
aA.visitor = Visitor.getInstance("companyname");
In addition, there were also some issues using my localhost for testing while trying to see if I had this correct or not. If you are having issues and think you have it correct, it may be worthwhile to elevate it to a different environment.

Determine tweet location with Twitter API

How can I find the location of a specific user's tweet? What are the API methods and techniques that I need to go through to determine the location?
Note: The below assumes that you want to grab multiple tweets and find their locations. If you don't, and you just want a single tweet by it's id, use statuses/show.
It's entirely possible - if the user has enabled location for their tweet. It'll be the value of the coordinates key, which will be null if they haven't.
Let's say you're using the following API method: statuses/user_timeline.
This is a GET request
The resource url is: https://api.twitter.com/1.1/statuses/user_timeline.json
You can specify either the user_id or screen_name as part of the GET parameters, for example: ?screen_name=J7mbo.
In the tweet results, once json_decode() is run on them, one of the keys will look like this:
This is actually the first key, according to the documentation, so you should be able to find it and it's value pretty easily.
Warning
Do not get confused with the location sub-key underneath the User key. This is the location of the user, as per their profile, not the location of any specific tweet. Use the coordinates key for that.
Documentation Link

twitter search api no place returned

I am having a bit of trouble sifting through the twitter API. I am trying to search for tweets near a certain location and then see their exact (or approximate) geo coordinates. I understand the geo field is deprecated and now we are supposed to use the "place" field. Unfortunately when I use the following url: http://search.twitter.com/search.json?q=&geocode=30.1829,-97.832,10mi I get a bunch of responses with a location that matches the city of the geo coordinates, but geo: is null and there is no place field. Am I stuck with only having an accuracy up to city coordinates, or am I using the wrong search call?
Thanks in advance!
Remember, tweeting with a geo location is an opt-in process. Twitter will supply a feed from the area for all tweeters in that area, but only those who have opted to tweet their coordinates will show up with "geo" info.
Using q=here with your url it did return 1 tweet for me with "geo" info in this form (though likely it will have moved on down the timeline by the time you try...):
"geo":{"coordinates":[-33.9769,18.5080],"type":"Point"}
Every user has a user defined location set in their profile settings. Use this when users don't use geo-encoding.
You can obtain a list of all countries / states by country and do a simple clean-up operation on the dataset.
This gave me what I needed for location data and greatly enriched my output.

Django URLs - How to pass in multiple caterories via the clean URL without the need for?

I want to stay way from GET params. Don't want to use POST and I have at least two different categories to build the URL for.
The visitors are first asked to choose a location wich can be one of, for example:
http://foo.com/United-States/ ||
http://foo.com/United-States/California/ ||
http://foo.com/United-States/California/San-Francisco-Region/ ||
http://foo.com/United-States/California/San-Francisco/
Once a location is selected, then they can pick a category which can be one of for example:
http://foo.com/Electronics/ ||
http://foo.com/Electronics/Camera/ ||
http://foo.com/Electronics/Camera/Digital/ ||
http://foo.com/Electronics/Camera/Digital/SLR/
So, how would I go about combining both of the above URL in one, once they are done with selecting the location and the category?
I might need to pass in the page number for pagination. (http://foo.com/page/2/)
I'd like to keep the URL clean and self explanatory.
I know how to do one type of URL at a time but not combining multiple types.
If I were to do a GET, then I would be doing: http://foo.com/?locid=23323&catid=335&page=2, but I like to take advantage of Django's clean URL and stay way from the ?& stuff.
Thanks,
VN44CA
I think that this would be to many information in the URL. I assume that any location has its unique ID, the same goes to category. Why not build a URL:
http://foo.com/United-States/Electronics/
http://foo.com/California/Digital/
http://foo.com/San-Francisco/SLR/
and so on...
2 arguments are enough in your case. Or you can change category name to be more meaningful.
http://foo.com/Electronics/Camera/Digital/ => http://foo.com/Digital-Cameras/
Depending on how you are using the location data, and how often a user will want to change the location, it may be best stored in the session instead of having it specified in the URL.
For example, I am unlikely to start off looking for SLR digital cameras in San Francisco and then go looking for basketballs in Baltimore.
Obviously this won't be sufficient if you want permalinks to any location-category combination, though.
After thinking about this for a while, I found that the best solution (for me) to this is to have a string just hold all the arguments that I need in a clean URL.
So, when users first come to http://foo.com/ they are presented with a locations to select. Cookies are empty at this point.
So, a user goes ahead and selects United-State, the URL will look like http://foo.com/12334_0_0_0/United-States/ and the location cookie is set to 1234 which is the id for location United States.
Now the user selects California and the URL changes to http://foo.com/1235_0_0_0/United-States-California/ and cookie is replace from United states to 1235 which is the id for the location California. At this point the user selects Category Electronics. so the URL changes to http://foo.com/1235_3333_0_0/Electronics/ and 3333 is saved in the Category Cookies.
If the users drops down to SLR Camera, then s/he'll see http://foo.com/1235_3344_0_0/SLR-Cameras/.
This way, the first portion of the URL keeps track of up to 4 arguments which can be passed around and the names (slugs) are merely for presentation and SEO.
I think this would work right? It would be cool to have the x_y_z_p portion of the URL encoded into some random text and decode back into args & numbers.
Let me know what you do think?

Resources