Twitter API code to find specific cities - python-2.7

So far I have this code:
with open("real estate data.csv", "a") as myfile:
myfile.write('"{0}",'.format((tweets.user.location).encode('utf8')))
Which can find me the location of users on the Twitter API when they make a Tweet.
However, it returns broad locations such as New York, but what if I wanted to find specific cities or areas, like Times Square, New York instead of all of New York.

The latitude and longitude coordinates are specified under the coordinates field, however those coordinates are only specified in case the user explicitly shared their location while tweeting.
To access it simply use tweet.coordinates, here is an example:
"coordinates":[-97.51087576,35.46500176]
Read more about coordinates in the doc.
This used to be part of the geo field which is deprecated now so it will always be equal to null.
Read more about how geolocation works within the Twitter API here.

Related

Map locations from ASA to powerbi

I have a Stream Analytics job that generates locations latitude and longitude to powerbi. I am trying to create a map on powerbi.com from these locations. I am creating a map diagram and adding latitude and longitude fields to maps latitude and longitude fields. But nothing is generated. It is expecting some Location field as well. What data should I provide there?
Yes. You need something in the Location field (but it can be a timestamp or an ID or anything). That's what decides how many bubbles you have. Then for each bubble it does an average latitude and longitude to determine where to put the bubble.
The location field is to specify a "City" location rather then specifying it giving coordinates. If you provide "London" for instance it will create the shapes at the center of London as defined in the maps provider.
On the Long and Lat side, they have to be in a specific format for PBi to recognize them as map fields.
Take a look at the links below for further info on how to change the data type using the editor.
http://community.powerbi.com/t5/Desktop/How-to-map-latitude-longitude/td-p/2479
http://www.radacad.com/how-to-do-power-bi-mapping-with-latitude-and-longitude-only
Hope this helps.

Post status update with location

When you post a regular status update to Facebook, it tracks your current location and gives the (near) city next to the time. I.e.: May 24 near New York City, New York. Please note that this is not a check-in.
I'm trying to do the same, without searching for a page (place) id and checkin.
I've tried posting the coordinates with latitute and longitute, but it doesn't show the near city.
https://graph.facebook.com/me/feed
message=test
coordinates={"latitude": 37.4163458217, "longitude": -122.15198690595}
please check this url
https://developers.facebook.com/docs/reference/api/status/
you have to pass the coordinates as an object called place , and that will have the details about the place , few more details about place object ...
object containing id and name of Page associated with this location, and a location field containing geographic information such as latitude, longitude, country, and other fields (fields will vary based on geography and availability of information)
I realize this is an old question, but just to confirm, posting via an app can only let you tag a place using the place ID.
Please check these related posts -
https://developers.facebook.com/blog/post/2012/03/07/building-better-stories-with-location-and-friends/
https://developers.facebook.com/docs/opengraph/actions/#taggingplaces

GeoDjango/PostGIS/Concept: How to connect user entries to shapefile information?

Hi Stackoverflow people,
I am working on an organisation registration, in which orgs can register their project areas (like all Nevada, entire US, or simply a city e.g. Boston) and users should find all organisations which are covered by the organisation according to their lat & lng.
What is the best way to connect the organisation information with the user searches?
Is the following process ok or do you have any suggestions:
I load the shapefiles of all necessary states, counties , etc. in
my postgis database
If an organisation adds "New York state" to
their coverage area, I would look up the polygon shape for the state
(or the id to the shape) and save it in my coverage table
When I search for the org coverage, I would find all projects where the
user lat & lng is part of
Is that process above ok to connect the user information to the shapefile information?
How can I look up polygons in the shape files? Can I reference them with an ID?
How would the lookup work with cities, since most lists with city name, lat, lng only list the center point of the city? Or is there a table for even city boundaries?
Thank you for your help and suggestions!
When you import a shp file to postgis with shp2pgsql, all the other columns (state name, city name, etc) are imported too, so you can search by name or any other property that the shp file has, or you can search by geometry, if you have a point and you want to search polygons or points(citys in your case) near that point, the query to the database is very simple:
SELECT * from myTable where ST_DWithin(users_point, the_geom, 0.002);
//the distance units of ST_DWithin are in the geometry units.
PS shp2pgsql automatically creates a serial column(unique id)

How to find if lat/long falls in an area using Django and geopy

I'm trying to create a Django app that would take an inputted address and return a list of political races that person would vote in. I have maps of all the districts (PDFs). And I know that I can use geopy to convert an inputted address into coordinates. How do I define the voter districts in Django so that I can run a query to see what districts those coordinates fall in?
This is a non-trivial problem too large in scope to answer in specific detail here. In short, you'll need to use GeoDjango (part of contrib). There is a section dedicated to importing spatial data.
Once you have your data loaded, you can use spatial lookups to find what district a particular coordinate intersects.
As to where to get the voter district data, you might start with www.data.gov's geodata catalog.

Using Geo APIs to pick a random town from anywhere in the world

I'm trying to use Yahoo's excellent GeoPlanet API:
http://developer.yahoo.com/geo/geoplanet/guide/api-reference.html
I would like to pick a random town from anywhere in the world but can't see an easy way to do it. I have tried querying by country and asking for children of type 'town', but can't seem to do that directly.
Can anyone think of a way to pluck out a random town WOEID without having to query the country, then the admin regions, then the admin 2, then the admin 3 etc.
I have also experimented using YQL, but don't have enough of an understanding about the available APIs.
Have a look at http://world-gazetteer.com/.
You can store all towns in your local database, then do random select, and then just geocode selected town using any geocode service you like.
Just for phun, why not generate random lat/long & display whatever is there?