Working with google maps api - google-maps-api-3

I am trying to build a map based query interface for my website and I am having difficulty finding a starting point besides http://developer.google.com. I assume this is a rather simple task but I feel as though I am on a wild goose chase. Anyway the problem is the existing site places people into a category based on their address (primarily the zip code), this is not working out because of odd shapes and user density so I would like to solve the problem by creating custom zones.
I am not looking for a proprietary solution because I would really like to accomplish this on my own, I just need some better places to start or better suggestions for searches.
I understand that I will need to create a map with my predetermined polygons.
I understand how to create a map with polygons via js.
I do not understand how data will request which zone it is within and how it will return it as a hash I can store. eg. user=>####, zone=>####, section=>#####

http://blog.appdelegateinc.com./point-in-polygon-checking-with-google-maps.html
has some JS you can add to give the ability to test whether a point is within a polygon (sample: http://blog.appdelegateinc.com./static/samples/point_in_polygon.html ) using this approach: http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm
I think as you place the markers, you'll hold them in an array (of objects)...then loop through, doing some sort of reduction of which polygons to test, testing those that remain, if inPoly, set marker.zone and marker.section to whatever suits your needs

Related

OpenLayers ::: Counting the houses in a polygon?

I need to be able to count all the houses/addresses that exist inside a polygon. I've thought it through and it seems possible to find if a single address exists inside a polygon (by finding if the geolocation intersects with it?)
Is it possible to pull a list of all the addresses in an area and check if they intersect? Or might there be some other method?
If I were to try to do this on the browser client, I would get an array of OpenLayers.LonLat objects or OpenLayers.Geometry.Point objects. I would iterate over that array and ask if each object was within a polygon by calling the containsPoint function of OpenLayers.Geometry.Polygon. I would count or collect the points that fall within the polygon.
Geospatial operations like you are describing are something we do on the server using open source GeoTools. We tend to use OpenLayers almost exclusively for map visualization.
I may have not answered your question entirely because I sense you are trying to get that list of addresses/points in the first place for an area on the map, and I don't think you've provided enough information to answer that part of the question.

Routing Engine Using OpenStreetMap Data

As part of my academic project, I have to build a routing engine based on data supplied from OSM. I have looked at the data model of OSM and I'm all fine with it. However, I'm having trouble converting an OSM XML file into a graph structure (nodes and edges) that I can use to apply search algorithms (Dijkstra, A* etc.) on. I would like the graph to be stored in memory to allow fast read/write.
So can anyone shed light or suggest techniques on how this can be done, or even provide pointers for further research.
Please note that I'm not allowed to re-use existing routing engines as this would defeat the purpose of doing the project.
All you need to do is:
create a node for every <node> item
every <way> entry is a sequenced list of <nd> items, each of which is a backreference to a node. So for each <way>, you iterate pairwise through its <nd>s and create an arc between the two nodes referenced.
You can do this in one pass using a streaming XML parser, since the XML data defines all the nodes before the ways.
The data doesn't intrinsically include distances, so you need to calculate that from the latlon of each node. You should also take account of the road type (highway=*) and the access info (access=*) in your routing, and you probably also want to ignore ways that are not traversable (eg waterway=stream) but that's all down to your specific situation.
http://wiki.openstreetmap.org/wiki/Elements

Mapping GPS coordinates to an area

I have devices moving across the entire country that report their GPS positions back to me. What i would like to do is to have a system that maps these coordinates to a named area.
I see two approaches to this:
Have a database that defines areas as polygons stretching between various GPS coords.
Use some form of webservice that can provide the info for me.
Either will be fine. It doesn't have to be very accurate at all, as i only need to know the region involved so that i know which regional office to call if something wrong happens with the device.
In the first approach, how would you build an SQL table that contained the data? And what would be your approach for matching a GPS coordinate to one of the defined areas? There wouldn't be many areas to define, and they'd be quite large, so manually inputting the values defining the areas wouldn't be a problem.
In the case of the second approach, does anyone know a way of programatically pulling this info off the web on demand? (I'd probably go for Perl WWW::Mechanize in this case). "close to Somecity" would be enough.
-
PS: This is not a "do the work for me" kind of question, but more of a brainstorming request. pseudo-code is fine. General theorizing on the subject is also fine.
In the first approach, how would you build an SQL table that contained
the data? And what would be your approach for matching a GPS
coordinate to one of the defined areas?
Asume: An area is defined as an closed polygon.
You match the GPS coordinate by simply calling a point inside polygon method, like
boolean isInside = polygon.contains(latitude, longitude);
If you have few polygons you can do a brute force search through all existing polygons.
If you have many of them and each (ten-) thousands of points, the you want to use a spatial grid, like a quadtree or k-d tree, to reduce the search to the relevant polygons.
method.
this process is called reverse geocoding, many services providers such as google, yahoo, and esri provide services that will allow to do this thing
they will return the closest point of interest or address, but you can keep the administrative level you are interested in
check terms of use to see which service is compatible with your intended usage

Find nearest locations from json Sencha Touch 2

I'm trying to setup a portion to my app where the user's mobile location (which I have working) is used to find the nearest locations (lets say within 15 miles) against a json store of locations (lets say of 40 or so and it will increase).
I've been racking my brain how to go about this. I believe Distance Matrix (looking at the Google API, but no idea how to implement it from the docs) is something I need, but I can't figure how to load the json list and use it against the location (still a n00b).
If there's a tutorial or some details on how to go about it would be great. I just need a point in the right direction.
Any info is great, thanks ahead of time.
I'm using Sencha Touch 2.0.1, a json store and using the Google Maps JavaScript API v3.
Matt
You'd be better off doing that processing on the backend and sending only the close records back to the client. This will keep your client app from getting bogged down.
You can use Postgresql/Postgis for this if you store the lat/long points as spatial data. You can also do this with the MySQL spatial extensions. If you want to build the haversine formula into a MySQL function, you can draw 15 mile radii around all of your points and use MySQL's builtin 'within' function. If you'd rather use a flavor of NoSQL, then CouchDB has a nice GeoCouch extension which can perform the function you desire.
Yea, figured out a way. More than likely not the best, but it'll work for now.
I'm loading all the latitudes and longitudes with the locations into the store file.
Then, on initialize, it takes the current location and matches it against the stored locations and runs the Haversine formula with each one. Once it has all of the distances, it sorts and done.

Need a resource for pairing cities to coordinates

I have a list of cities (and some other locations) around the world, formatted like this:
America/Antigua
America/Anguilla
Europe/Tirane
Asia/Yerevan
America/Curacao
Africa/Luanda
Antarctica/McMurdo
And I need to get their corresponding coordinates formatted like this:
Europe/Stockholm 59.21N 18.04W
Since I have a rather large list (around 1k posts) I would like to be able to automate the retrieval of these coordinates. Does there exist a free resource (preferably downloadable, not search-only) from which it's easy to extract this data?
The alternatives I can think of at the moment are google maps (which would require an api key, if I understand it correctly), or Wikipedia (which doesn't have that data easily available, and is not optimized for that kind of searches). And both of these are online-only, which is sub-optimal for me.
Look at geonames.org
I am sure you can query that service for free but I dont know if that data can be downloadable
Check out http://www.realestate3d.com/gps/world-latlong.htm

Resources