Get Zip Codes within a range in a given Longitude-Latitude - javascript

Im working with the google-mapquest mapping API. I need to add some Points of Interest near a certain area from a given latitude-longitude location.
I search the google and mapquest documentation to figure out if there is a method to get all zip-codes in that area but i didnt find anything that does that.
I tried the harvesine implementation to calculate the nearest point given in that radiuos/latitude-longitude and it works fine. The problem with this approach is that i need to update constatntly the database, so i dont like it much.
The question is: Is there a service (google-mapquest or another) that gives you this information?.

No, there is no API for either service that I am aware of. Your best bet is to just get a ZIP Code database and use that. Some really good inexpensive ones are out there. I prefer http://www.zip-codes.com/zip-code-database.asp. Their $40 package is very accurate, updated monthly, and licensed by the USPS (so you know it's quality data).

UPDATE:
I found a WebService that does exactly what i need. You could provide only a simple ZipCode and a country or perhaps a full address and in the response you get the longitude/latitude. Then i send the Latitude and Longitude returned to get a list of all the ZipCodes near the provided coordinates and a given Radius that also can be customized.
You can filter the total rows you want the service to return, or even if you are gonna use miles or kilometers as the measure unit.
So, basically with the returned information, i feed those coordinates for each of the nearest ZipCodes obtained to the google API and render those points of interest into the map that you need to show.
The services are provided by GeoNames. Its an organization dedicated to Geolocalization services. They offer also premium data, but in particular these services are free of use, obviously the information is not as accurate as the premium one, but actually in my tests i found that that is trustful and the response also is very fast.
Another good advantage is that the process to get a Key for use Geonames services it's quite simple.
I left you the link of the services that i'm talking about.
List of available services:
http://www.geonames.org/export/web-services.html
Hope it helps many people.
Regards!

Related

GPS location tracking in laravel

I am currently working on a University project and I am going to create a hitch hiking mobile app. I am looking to use phonegap and Javascript on the front end and laravel as my RESTFUL API. I have looked at he Google maps API documentation but I have still not seen a plugin for Laravel which allows GPS route details to be stored on the backend in laravel.
I presume the mapping of routes between drivers and hitch hikers will need to be done on the server as details of all routes (journeys) will need to be stored and for searching.
Has anyone ever worked on a similar hitch hiking project and how would you check if a hitch hicker's route matches with a Driver's route. Surely this mapping must be done on the server and is there any API for Laravel that supports this?
My interpretation to how your service will work is that both hitch hikers and drivers will state their current location and their intended destination, and hitch hikers will be able to request rides based on matching routes/destinations (which is a pretty cool idea actually).
Based on that interpretation, here's how I might go about implementing it.
1. Create a Journey
A Journey model would be a the journey the user wishes to make. It would be comprised of many Waypoint models (at least 2, the minimum being the start and end points).
There would be a one-to-many relationship between a Journey and Waypoint.
A user creates a Journey and you use the Google Maps Directions API to store the Waypoints for it.
2. Periodically update a user's location
A user will eventually move between waypoints. When they do, you want to know where they are so you can update their position so that they're able to be accurately represented on a map of active users (I imagine you'll have one, displaying the locations of various Drivers and Hitchhikers, similar to Uber).
3. Match users based on similar waypoints
Use the waypoint data you have stored against a driver and hitchhiker's routes to find similar routes/journeys and make suggestions as to which hitchhikers a driver may pick up. You can even use the API data to give estimated times of pickup based on the distance between the driver and the hitchhiker.
There's more to consider, but that'd be a pretty decent starting point.
You would want to think about re-routing (what if a user can't go between certain waypoints due to roadworks, or perhaps they take a wrong turn - think about how your SatNav might handle it), perhaps the ability to plan trips in advance, etc.
To actually answer your questions, yes, if you wanted to use Laravel for this you'd map the routes and match the waypoints server-side.
Let's take the scenario where I am a hitchhiker.
I want to get from A to G.
I'm currently at waypoint C
Driver X is on another route which happens to have my waypoints C, D, and E in it. To find Driver X, you could do something like (pseudocode):
// Find a driver with similar waypoints
Driver::withSimilarWaypoints($myJourney->remainingWaypoints())->all();
// withSimilarWaypoints scope
function scopeWithSimilarWaypoints($waypointsCollection)
{
$query->whereHas('waypoints', function ($query) use ($waypointsCollection) {
$query->where('passed', 0)->whereIn('waypoint_identifier', $waypointsCollection->pluck('waypoint_identifier'));
}
}
In this case waypoint_identifier would have to be the same for me and Driver X, so perhaps a hash of the waypoint object or you could use place_id as returned by the API.
You'd also want to make sure you're not matching against waypoints you've both already passed (hence remainingWaypoints() and where('passed', 0).
Driver X is estimated to arrive at waypoint C in 8 minutes, so I decide to wait for them (or I can request a lift via the app)
All that should be a pretty decent jumping off point for your service. I quite like the idea – good luck!

Geocoding information from a web crawler with Javascript

I've built some web crawlers to gather information about Hijacking Hotspots in South Africa... I've retrieved location information, but its all listed in a vague format, e.g.: "The William Nicol Drive offramp from the N1 from the Sandton side" ... Each location is formatted in JSON format right now.
My Problem:
I want to iterate through a list of all these descriptions/locations and retrieve rough GPS coordinates for each one. Would using the Google API with Javascript be the best option for achieving this? And does anyone have some code examples to demonstrate how I should go about getting this done with Javascript. Please keep in mind that I'm only an intermediate Javascript coder.
I need the quickest most efficient method of getting this done because I'm on a tight deadline and I'll have to use this method for a few other purposes as well.
Sample JSON Data:
{"data":{"area":"Cape Town","location":"Corner of Alice St and Voortrekker Road", "gps":"?"}}
It would be great if you can provide a sample of your JSON response.
The Getting Started page for Maps API have samples that will guide you through the whole process of what you want to develop.
The easiest way to do it is if the JSON response you have have lat/long coordinates. This way, you iterate through the items and place Markers to the map.
If no coordinates are available, but there's a placeId on the response, you can try out the Places API. You'll just need to provide the placeId in PlacesService.getDetails() and the response will contain an object with the lat/long coordinates - which you'll add into the marker.

Return a list of Google Maps locations that I have previously specified

Let me begin by saying, I have been searching for resources for this question for more than 3 days, so I truly hope I did not miss an "answer" anywhere.
Background:
I am working on a website/app built in HTML/CSS/Javascript that will use geolocation (Google Maps & Places API) to find a users location and return them the (for example) top 5 closest water parks to them at that location they are currently at.
Question:
I want to control the list of results the API picks from. So let's say, it'll only give them 5 out of 30 water parks that are near them and I have previously specified the names/locations of those 30 water parks.
The reason I want to do this is because after searching via Google Maps for "water parks nearby 123 Main Street, City, State" - it doesn't return all the results I want it to, just some.
As I stated, I have looked far and wide for this answer. I have read almost all of the relevant Google Places API and Maps API documentation with no clear cut answer. I have also found a few website that let you use a Google Docs spreadsheet to specify locations, but you can't get the code from them. And I have seen a few example using XML, but nothing exactly what I'm looking for.
I will also note that I am familiar with C# and PHP if that helps get me closer to my goal. But it seems like Javascript is the way to go.
Any help/hints/tips would be greatly appreciated! Thanks!!
Store the data in a database that supports spatial queries(may be a FusionTable for example), then you may use ST_DISTANCE to order the results by distance and LIMIT to limit the resultset.

Does Google Maps API offer a way to search for locations by name?

When one visits http://maps.google.com, they are able to type queries into the search field and receive results based on locations or places, and not hard search results, as they would in a normal Google Search query. They're a unique style of result (names of places, locations) suited to the Maps interface for obvious reasons.
I've been digging through both the Maps and standard Google Search API for a couple hours now, and have done multiple searches on this question, and I can't seem to find the answer.
They obviously have the Local Search, but that's been deprecated, and it only yields results if you provide an initial lat/long. I want to be able to find places or locations with no initial lat/long.
Essentially what I want to do is allow a user to type in an address, name of a place or name of a city or state or a zip code, or essentially any other kind of location that is allowable on Maps, and geocode it. I feel stupid because this seems like it has to be there, but nothing I've seen in the API seems to do this.
I don't need the AJAX suggested results, necessarily. Just a way for a user to type in a nice name and geocode from it, though results as a user types would be ideal.
What am I missing here?
What you are looking is Geocoding API from google maps.
Find Documentation here
UPDATE 5/12/2011
Google just opened up public access to their Places API. This is more to the heart of the original question request:
https://developers.google.com/maps/documentation/places/web-service/autocomplete
I think you're looking for the google.maps.Geocoder class:
A service for converting between an address and a LatLng.

Use the Google Maps API to search within a predefined set of data

My client has a list of store locations. Now what he wants is to let users search for any of these locations, based on the address the user submitted. The search results will be based on the proximity of the locations.
So basically what I am looking for is Google Maps functionality, but based only on the set of (geographical) data I provide.
Do any of you know if this is even possible, and if so, what can be a good starting point to learn more about it?
Thanks in advance.
Sure it is possible. I guess you have in you database set of the latitude and longitude entries for each store. You can get users current location with geocoder and measure distance with distanceFrom call to find the nearest store.
You're welcome to copy the code directly from here, it does exactly what you request.
You'll need offices.htm, offices.js and logo.png.
To prepare your list of offices, you might find this Excel addin useful

Categories