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
Related
I'm pretty new to Javascript, but I want to create a simple app. It must show the name of the closest gas station when a button is clicked. It also must print it using document.write().
I have been looking at the documentation that Google has provided and I am confused about how to use rankBy.DISTANCE routine.
Any help would be appreciated. Thanks!
Get the longitude and latitude of your location through javascript. According to it check whether is there any gas station available within your preferred area. You can get the javascript api from Link is here
To use rank by closest distance see this
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.
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"
I'm using the Places Library to search any type of nearby places by keyword within a LatLngBounds rectangle.
For example if I search for pancakes I'll get restaurants with pancakes on their menu but it will also throw in an establishment with no relation like a juice bar.
How can I get the most accurate results by providing only a keyword? My nearby search request looks like this:
var request = {
bounds: my_bounds, //The bounds within which to search for places
keyword: document.getElementById("keyword").value,
rankBy: google.maps.places.RankBy.PROMINENCE
};
I know that I can also specify a type in the request but that means that the user will have to choose an option from a list of types and I wish to keep search options as minimal as possible. Any kind advice is welcomed!
I am really being selfish here and trying to find an answer to my post - but this question may be related and someone may be able to shine some more light on it for both of us.
I have noticed on a normal Google maps search (i.e. manually in a browser) if I search for: xxxxxx loc: yyyyyyyyyy where xxxxxx is a category such as "university" and yyyyyyyyyy (note the key "loc:" - for location in the middle) is the address I want to search around I get pretty accurate results. I just tested on "pancakes" and same thing. Also many of the sites have a "Category" which lists "pancakes" (or "university") that seems to show a closer match to what is wanted and/or that could be filtered on - better than using "type" or "name". This search also give distance to - which I want but which may not be important to you.
If anyone knows how to do such a "loc:" based search from the APIs that might be the answer to our questions (or maybe just mine)?
Hi is there anyway using Javascript to get user's current location and autocomplete fields in a form like telephone country code (e.g. in Singapore it is +65) and area code?
It's really difficult, and I'd advise against it because it's loads of effort for very little reward. The best way (most fluid for the user) would be to get the users IP using PHP/ASP/Ruby-on-Rails/whatever and query one of the freely available Geo-IP databases (Google it) to match that to a country, then create your own database of country codes (using this, or similar).
If you really really want to do it using JavaScript, it'll only let you do it in newer browsers, and it'll prompt the user that you want to know their location... a lot of people will wonder why you're asking for this and click no.
// first, check it's supported
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(insertCountryCode);
}
insertCountryCode is a function that you pass. Why? Because the prompt for the user to allow your website to know their location is non-modal, meaning the page will carry on running while it waits for a response, so the function when they do respond will be asynchronous (outside the normal flow). This function is where you look up their location and insert their country code. In this function, use the Google Maps API and pass the latlng parameter to get the country... then you need to find another lookup service which will let you find out the dialing code.
The reason I've explained this is to show you how hard it is. A much simpler alternative would be to have a drop-down box with
<option value="+65">Singapore</option>
and insert the value into the phone number box. That's what I advise you do.