Standard GPS Coordinates to lat/long/zoom used by MapBox - python

I'm brand new to MapBox, but like the images it produces, and want to be able to use their API to render some GPS points nicely.
Given a Standard GPS point (and a MapBox zoom level), how can I find the Lon/Lat values for a suitable MapBox 'tile' ?
The actual code that I'm trying to use is the Python code at:
https://github.com/mapbox/mapbox-sdk-py/blob/master/docs/static.md#static-maps
And my starting GPS point is in Auckland New Zealand -36.8,174.7.
https://www.google.co.nz/maps/place/36°48'00.0"S+174°42'00.0"E/
I have naively tried entering "standard" GPS coordinates:
from mapbox import Static
service = Static()
response = service.image('mapbox.satellite', lon=-36.8, lat=174.7, z=10)
but this results in the error message:
mapbox.errors.InvalidCoordError: Latitude must be between -85.0511 and 85.0511
Searching for this error message led me to this:
https://en.wikipedia.org/wiki/Tiled_web_map
But I still have no idea how to determine the long/lat values of a suitable tile. Any help would be appreciated.
Thanks in Advance
Patrick

The error message indeed right: mapbox.errors.InvalidCoordError: Latitude must be between -85.0511 and 85.0511
You got your coordinates reversed. The following coordinates -36.8, 174.7 stand for Latitude and Longitude, and not the other way around. So your code should be: service.image('mapbox.satellite', lon=174.7 lat=-36.8, z=10)
This can be seen from your Google Maps link: https://www.google.co.nz/maps/place/36°48'00.0"S+174°42'00.0"E/. Latitude guides you from South (negative) to North (positive). Longitude guides you from East (positive) to West (negative). Pay attention the Google link says: 36°48'00.0"S +174°42'00.0"E`. More information available here https://en.wikipedia.org/wiki/Geographic_coordinate_system
Searching for this error message led me to this:
https://en.wikipedia.org/wiki/Tiled_web_map
But I still have no idea how to determine the long/lat values of a
suitable tile. Any help would be appreciated.
Thanks in Advance
You don't need to. Mapbox's API abstracts that away for you.
Take a look here: https://www.mapbox.com/api-documentation/#retrieve-a-static-map-from-a-style

Related

Google Maps Places API radius parameter not working

I am using Google MAPS API in python:
https://github.com/googlemaps/google-maps-services-python
To get the information about a place I am using
result = gmaps.places("restaurant",location=(lat,lng),radius = r)
Now on changing the radius r to different values( I have tried for as low as 1) I always get 20 results. This is not possible, because you cannot have 20 restaurants in 1 m. Any fix for this?
Thanks for help!
I am afraid that it is posible cause the API is intended to work like that, as stated in the documentation:
"a location and a radius — You may bias results to a specified circle by passing a location and a radius parameter. This will instruct the Places service to prefer showing results within that circle. Results outside the defined area may still be displayed. "
Taken from:
https://developers.google.com/maps/documentation/javascript/places#TextSearchRequests

Use Tweepy to gather Tweets with hashtags from Egypt

I am using Tweepy and Python to gather tweets from Egypt.
The tweets must contain hashtags.
I am using these co-ordinates for Egypt:
25.13671875, 22.0245456012, 35.3759765625, 31.3723991049
The code is not a problem, but I am finding that I am only getting one or two tweets every few seconds, yet when I change the location to UK I get loaddsssss.
Anyone know whats going on please? Are my coordinates wrong?
Some people may say RTFM... :-)
because according to the last tweepy documentation:
The parameter value is specified by “latitude,longitude,radius”
But in your example you set twice a GPS coordinates ...
So it explain the result you got, because in my opinion tweeter API understand your request like :
"I would search all tweets, in a radius of 35.37mil (by default) near: 25.13671875, 22.0245456012"
So you may swich your coordinate request to :
25.13671875,22.0245456012,1000mil #mil or km as you prefer
then It will be OK !
*To explain the diff.: latitude of England is around 50.85300: so the same request applied to England coord give you all tweets in a radius of 51mil near the central point you choose...
Best regards

Geolocation of a tweet

I am using Tweepy (python) to access to Twitter Search API, and I am looking to extract the geo-coordinates of the tweet.
As you can see in the screenshot, I found geo and coordinates, and they are inverted.
I would like to know if I am in the good track first, then how can I distinguish between Latitude & Longitude ?
If it's not in Antarctica, the -80.xxxx is longitude. For longitude, the US is like ~79-80ish to ~120 something (I'm approximating). It seems like the first value in 'coordinates':{} is longitude, whereas the first value in 'geo':{} is latitude.
"coordinates" is the official field for this info while the "geo" field is deprecated. So ignore the geo field. For further details see this discussion http://bit.ly/1sM62oH
You would need four data points for a bounding box that can be found from OpenStreetMap. For example the coordinates for Madison is as follows:
twitterStream.filter(locations=[-89.566389,42.998071,-89.246452,43.171916]) #Madison, WI

Google geocoding: points of interest within a specified radius

After searching around it appears that many people already have the lat/long data of the geographic points of interest they are interested in reverse-geocoding.
In my scenario I know a starting location and would like to find all points of interest (mainly residences within a neighborhood) that lie within a specific radius (say, 1 mile).
The first step is simply specifying a starting point and a radius to search within but I can't seem to figure out how to do this using the the Google Geocoding API (I'm not tied to Google... just figured I'd start there).
I am currently working in python (geopy and pygeocoder) but will eventually port it to iOS.
Any pointers would be much appreciated.
I think you may be going down the wrong path with the Google Geocoding API. What you probably want to use is Google Places API.
One (simplified) way to think about is geocoding takes in a point and returns a point. What it sounds like you want to do is pass in an area, defined by a central point and a radius, and receive a collection of points contained within that area. It looks like the Google Places API can help you with that.
Have you considered using OpenStreetMap for your task? With the help of the Overpass API you can query for all data within a given bounding box. For example this query returns all data within the current view. It uses the overpass turbo for visualization and the Overpass API only in the background but of course you can also use the Overpass API directly for returning raw data as XML or JSON.
You can even specify which exact data categories to return, for example all shops selling clothes. Take a look at commonly used tags and the Overpass API language guide for more information.
In case you haven't already, check out Radar Search & Nearby Search
https://developers.google.com/places/documentation/search#RadarSearchRequests

Map of all points below a certain time of travel?

My question is very simple and can be understood in one line:
Is there a way, tool, etc. using Google Maps to get an overlay of all surface which is below a certain time of travel?
I hope the question is clear, but I coulnd't find anything related on the web.
If you have any information, I'll take it!
Here is what I mean illustrated by an example:
I search for a new place to live. I know the precise address of my office.
I would in this case be able to overlay on Google Maps the surface which is under a certain time of travel (let's say 30 minuts by car).
We would have a long surface colored around motorways (because you get faster), and colors around roads.
I think you are looking for something like Mapnificient: it shows you areas you can reach with public transportation in a given time (video).
A similar site with even more options is How Far Can I Travel. Here you can choose between inputting your speed of travel and a travel time OR a distance. Optionally, you can also specify how accurate you want the results to be.
Now, how to create such examples yourself? See this related question where the accepted answer explains step-by-step, how you can get travel time data from the Google Maps API.
Finally, for $8.75, you can buy the article Stata utilities for geocoding and generating travel time and travel distance information by Adam Ozimek and Daniel Miles that describes traveltime, a command that uses Google Maps to provide spatial information for data.
The traveltime command takes latitude and longitude information and
finds travel distances between points, as well as the time it would
take to travel that distance by either driving, walking, or using
public transportation.
Other than the ones in #BioGeek answer, here are some more:
Nokia Here Maps API can give you the exact shape of the output. They call it time-based isoline. See here: Requesting a time based isoline
For travel times under 10 minutes, Isoscope is available at this address.
Also this looks promising: Route360
Update:
Route360 can be used for free in the following places:
Africa
Austria
Australia and New Zealand
British Isles
British Columbia
Czech Republic
Denmark
France
Germany
Italy
Malaysia, Singapore, and Brunei
Mexico
Norway
Portugal
Spain
Sweden
Switzerland
USA
I think you are looking for the Google Distance Matrix API. It returns not routes, but duration and distance for each pair of origin and destination. It has a usage limit of 100 elements per 10 seconds.
So you can make an educated guess about the distance that matches the desired time of travel, choose six or eight equally distributed points on a circle of that radius, and query the corresponding durations. Then refine the distances according to the results and calculate intermediary points. This way you can get a (quite rough) map in a few iterations.
I don't think there is a simple way of doing this, but here's an idea:
You'd need to first get the long/lat coordinates of your start position. You will then need to work out say, 50 coordinates around that start position that are say, 1 kilometer away from it (the answer here can help). You'd then need to traverse around each of these points and ask for the driving time to get there from your start position using Google Driving Directions API.
You'd then need to traverse the points again to find the points that are below the time of travel allowed (e.g. 30 mins in your question), move these points another kilometer or so away (in the same direction that the point originally moved from the start position) and repeat the driving time request until all are above the time of travel allowed. Finally you end up with 50 coordinates which you can plot onto a Google Maps image as a polygon using the Google Javascript API for mapping polygons.
This method requires a lot of requests to Google so you'll need to think about Google's limit on the number of requests you can do a day.
You can use the GraphHopper Directions API - this API part is also open source.
As we've added public transit and this feature recently it currently does not work together. But this is planned and until then you can enjoy road network isochrones :)
Disclaimer: I'm one of the GraphHopper founders.
You can draw a circle around your current position and check for a road at an angle every X degrees.
Another idea is to use a contour plot and isolines.

Categories