Convert Lat/Long into state - javascript

I know how to set up geocode and pull the user's lat and long coordinates. However how do I turn this into a state name or code ie(DE, MO FL). I've looked at using Google's reverse geocode, but am unable to get an API code. Any other way to go about this?

As the comments suggest the only way to achieve this is via reverse GeoCoding.
Here's a link to the API docs for reverse GeoCoding:
https://developers.google.com/maps/documentation/geocoding/
And an anchored link to the outputs, clearly showing the state:
https://developers.google.com/maps/documentation/geocoding/#GeocodingResponses
I've found some of the Google API docs somewhat confusing so I'd suggest searching for a worked example where someone has done something similar.

Related

How to get only street/road coordinates via reverse geocoding (Google Maps API)

I'm looking for a solution to get data to create a simple roads-only map.
Within a small area specified by lat/long I need data that allows me to draw custom lines between given street coordinates (start and endpoints are basically enough and only from major streets). Coordinates from intersections are also fine to connect those with my custom lines.
Another approaches would be to get all the major street names within the specified area via reverse geocoding and then - somehow - get coordinates for each of this streets.
There was a similar request a couple years ago:
Get street graph for a game using Google Maps API and I'm wondering is it still a big deal to achieve this kind of technical information in a simple way?
EDIT:
I researched the topic but no result gave me the satisfaction I was looking for. For instance Google's Directions/Roads API are both depending on routes. OSM/Google Maps API are filled with information around a specified geo location but without any technical data I need. To be simple: An Array of intersection/street-point coordinates (are they even called coordinates?!).
I think I'm lost - or even stuck - in terms of my own search phrases. I'm not looking for a copy & paste snippet more like a direction or some hints where to focus next or how it is done.
With the clarification of geocodezip's comment I've found the following related question:
How to get all roads around a given location in OpenStreetMap?
This fully suits my demand to get specific road information within a certain location using OSM instead of Google Maps API.
Many thanks

maps.google Geocoding Jquery calls with country codes

Im trying to get a simple geo-location type address lookup thing going using the google maps geocode API using jQuery $.getJSON method.
US & UK postal/zip codes are working fine but i've come across random countries where I'm guessing zip address are the same as other countries and i need to be able to return the correct address.
Im using a select option for someone to pick their country which contains its code e.g. Afghanistan has AF tied to it however when i try pass in the country code I'm still getting the wrong results.
Is there a proper way to call the API or are the results just hit and miss.
Sample below :
Zip for Kabul,Chahar Asyab is 1051
http://maps.googleapis.com/maps/api/geocode/json?address=1051&sensor=false
Will return addresses for Sweden,Slovakia and others countries but the one i want, I've looked briefly at the documentation and someone suggested region parameter in the URL however even with region=afit still returns different results.
Probably an easy fix but i've not found anything yet, i appreciate any help.
Thanks
Found a solution using
components=country:AF as a work around although the data is not always complete but works

Google Maps Directions - Find Out if Route Contains Toll

I am making a program that uses the Google Maps Directions Service. In my Directions Service Request I have set avoidTolls to false. But, I would like to know if the route contains tolls just like Google Maps:
I have seen this SO question:
Return if route has Tolls Google Maps API xml request
But because the question is over a year old, I am wondering if the Google Maps API has added a toll feature, might there be a different answer?
Is this possible? If so, how?
I'd love to see this feature as well. But Google didn't make any changes to this. So you still have to check html_instructions for certain words.
The best way is to force the language to "en" and then check if it contains "Toll road" or "Partial toll road".
Fail safe might be just to lowercase the html_instruction and search for "toll road".

passing an array of addresses into the Geocode.geocoder() Google Maps

Description:
I am using Google Maps v3. I have 25 dynamic addresses that I need to geocode at one time. We are currently working on a solution to store the lat/long in a database and remove the need to use Google's resources, but that is still a few months down the road and I need this geocoding functionality now.
Question:
Is there a way that I can send an entire array of full address into the geocode.geocoder() function? I have only seen examples where it was limited to one address at a time.
Disclaimer:
I have searched this site and could not find a solution. I have also google'd this exact question and haven't found anything.
The answer is: No
Some great alternatives: https://gis.stackexchange.com/questions/22108/how-to-geocode-300-000-addresses-on-the-fly
Not too sure if I should delete the question or not; kinda want to leave it up so duplicates aren't made. I would never have thought of the search query "batch processing"

Google Map Location constructor with general location type

I have been using Google maps api to get customer to a specific location using a constructor like this
new google.maps.LatLng(42.999, 54.000);
With the exact longitude and latitude as the arguments. What I want to do now is not use the lat, long option and use a keyword like rest area that would bring up the closet rest area. I am not quite finding it in Google map api here https://developers.google.com/maps/documentation/javascript/reference
Can some one help me come up with a constrctor that can take a key word and locate the nearest one in googLe maps.
You're going to have to use the google geocoding API.
Basically you do a request to google with a search string and it returns an object containing the long/lat for areas it may have found... There's a lot of options in there and you can do fairly neat tricks which are already carefully explained by google themselves.
https://developers.google.com/maps/documentation/geocoding/
There are some limitations to the # of requests you can make per-day. To keep this to a minimum you can ofcourse make a server side script that pre-fetches results for things that will be re-used (for example the long/lat for office location of a large enterprise which may have a dot on a map on the website...).
Simplest way would be to make a json request with a few parameters and parse the return json in js, like getting the long/lat of the first result returned.
If I understand correctly, you want to use keyword search for things around a particular location. I would suggest using the Places library of the Google Maps API:
https://developers.google.com/maps/documentation/javascript/places#place_searches
This allows you to search by category or by keyword over Google's datastore of 10s of millions of Places.

Categories

Resources