How to get `latitude` and `longitude` for an address? Google Maps - google-maps-api-3

I'm using http://gmap.nurtext.de/documentation.html library to display the map for my address field (mysql table)
How I can get the latitude and longitude for each address, for example:
I have this address: 'McLester road'
Note:
my visitor (user) who added the address (into Mysql table)

Enter the desired address into Google Maps.
Now, enter this into the address bar:
javascript:void(prompt('',gApplication.getMap().getCenter()))
This will return the longitude and latitude for you. Simply copy and paste these numbers into your code.
EDIT
Since this question is still getting some attention I'd like to say that nowadays most browsers will search for the text you put into the address bar, so instead it may be better to open up your browser's console and just enter a portion of the above code:
prompt('',gApplication.getMap().getCenter())
Also, if you just want the just the javascript object returned, just call:
gApplication.getMap().getCenter()
That way, you can do things programatically as well.

Google's geocoding sevice can convert address to coordinates.
There is a javascript api, but geocoding is available as a webservice too.

Related

Geocoding addresses with googleway: incoherent results

I am trying to geocode addresses on Google Maps using the google_geocode function from the package googleway in R. I am using a key obtained from Google that allows me to go over the 2500/day limit (and being charged for that). I have different types of problems, mainly due to the way the addresses I use are written, but there is one issue that I would like to ask here: how is it possible that I sometimes get no results querying with googe_geocode, but if I type the same address string on http://www.google.com/maps/ it does return a result?
My example:
address="AVENDAÑO, 30-32 VITORIA-GASTEIZ 01008, ES"
# the address I want to geocode. Its format is "street, number, city postcode, country" in a single string.
google_geocode(address=address,key=mykey) # I write the right key as mykey.
# I get no results:
$results
list()
$status
[1] "ZERO_RESULTS"
But, if search for exactly the same address string in Google Maps, I get the right location (showing that this is Abendaño Kalea in Vitoria, Spain):
https://www.google.com/maps/place/Abenda%C3%B1o+Kalea,+30,+01008+Vitoria-Gasteiz,+Araba/#42.8451894,-2.6855022,17z/data=!3m1!4b1!4m5!3m4!1s0xd4fc213d775d83d:0xc2a5f2ffa8721c2a!8m2!3d42.8451855!4d-2.6833135
Can anyone explain what may be going on? Maybe some staff from Google Maps or Google Geocoding API may help?
Thanks a lot,
Note that Google knows this street as 'ABENDAÑO, 30-32 VITORIA-GASTEIZ 01008, ES', so the B and V letters are important. I know that in Spanish language this is the same sound, but probably Google expects exact match.
According to the documentation:
Specify addresses in accordance with the format used by the national postal service of the country concerned.
source: https://developers.google.com/maps/faq#geocoder_queryformat
On the Correos.es I can see that the official street name is ABENDAÑO as shown in the following screenshot
So just use the following request to get results:
https://maps.googleapis.com/maps/api/geocode/json?address=ABENDA%C3%91O%2C%2030-32%20VITORIA-GASTEIZ%2001008%2C%20ES&key=YOUR_API_KEY
Or the same thing in geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3DABENDA%25D1O%252C%252030-32%2520VITORIA-GASTEIZ%252001008%252C%2520ES
I hope this helps!
I think it is likely that is due to encoding issues. I have had this happen when trying to geolocate addresses with "Ñ". Doing this worked for me:
string <- "AVENDAÑO, 30-32 VITORIA-GASTEIZ 01008, ES"
Encoding(string) <- "UTF-8"
google_geocode(string, key = key)
Since google changed their pricing scheme now you need to have an API key.

Store Locator API + Geolocation

I am trying to create a Store Locator with the Google API, very similar to the one in the Google examples here:
http://storelocator.googlecode.com/git/examples/panel.html
However I've hit a wall trying to get the Store Locator API to get the user's position through Geolocation, so when I click on Get Direction in the infowindow I get directions to the user position; instead of having to type my address in the: Where are you? Panel box.
In the documentation what I have seen is that geolocation is a boolean in the View Option that is set to True by default. But this does not solve my problem.
Does anyone have any idea on how to do this?
seems that the googlecode page you said is no longer exist. So I can't give any further insight about what you want to make.
However, by your description, Luckily I made similar site few months ago. It is on Grocery Store Near Me .
The concept of Geolocation is an HTML5 (actually W3C) Geolocation API which is now already embed in most modern browser. It is an API which you can obtain user's location (latitude, longitude, altitude, and accuracy).
you can call it with simply
navigator.geolocation.getCurrentPosition(success, error, geo_options);
Success and error is a callback function in which you can define.
In my case, the function looks like these
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// use the lat and long to call function to fetch an API through AJAX
fetchStoreData(latitude, longitude);
}
In the Store Locator schema (like mine in Grocery Store Near Me), Geolocation is used to obtains user lat and long. The lat and long, then send to server via AJAX to get data about nearby store location.
The server serve an API in which accept lat and long as parameter, then fetch the store data (either using database, or other external API like foursquare), then you can display it either on list, or on a maps.

Google Map API v3 not accurately returning Japanese addresses

I have a site implementing "Google Map API v3" to create a map with pushpins of the yoga studios in our DB. Unfortunately, the locations are all in Japan. We have the addresses in English and Japanese, however, Google Maps is not so flexible with Japanese addresses in English and our DB of addresses is not the cleanest, so sometimes addresses do not display properly. Our addresses in Japanese characters (kanji) are probably fine and I would like to use them, so here is the problem...
When using addresses in kanji with the Google Map API, the maps shows completely wrong locations. But when I input the same address manually in Google Maps, it accurately delivers.
Is there a language setting or something?
Thank you.
Update and another question...
I figured out how to get the correct locations onto the map by editing the 'GoogleMapAPIv3.class.php' file here:
public function geocoding($address)
{
$encodeAddress = urlencode($this->withoutSpecialChars($address));
$url = "http://maps.google.com/maps/geo?q=".$encodeAddress."&output=csv";
...etc...
Changed the '$url...' line to:
$url = "http://maps.google.com/maps/geo?q='".$address."'&output=csv";
To make the function just use the inputted address as is. My question is, will that cause any problems with anything else?
Keep in mind this map function is only used to map locations residing in our DB, so the addresses are only limited to what is there. i.e. no random user input.
Thanks again.
change $url = "http://maps.google.com/maps/ to $url = "https://google.co.jp/maps/ and if you want you can add language=ja at the end so that the language is japanese for example:
https://google.co.jp/maps/api/js?language=ja
https://developers.google.com/maps/documentation/javascript/examples/map-language
and https://google.co.jp/maps/ is google maps on Japan

Acquired the building name using GPS Coordinates

I am writing an app to use GPS coordinates obtained by the cell phone itself to retrieve the building name of that location.
For example, if I use this http URL to request with Google Place API:
https://maps.googleapis.com/maps/api/place/search/json?location=40.805112,-73.960349&radius=10&sensor=false&key="YourKey"
I can only get the street name of this coordinate through this.
But if I type "40.805112,-73.960349" in maps.google.com. I can get the exact building name. SO I was wondering how can I use Google Map API to obtain the building name I want.
Thank you very much about this!!!
The first result in the request you provided contains "name" : "Church of Notre Dame", isn't this what you are looking for?
A better request if you are only interested in the place name at this location would be to use the rankby=distance parameter instead or radius and to filter by type=establishment:
https://maps.googleapis.com/maps/api/place/search/json?location=40.805112,-73.960349&rankby=distance&types=establishment&sensor=false&key=YOUR_API_KEY
This would return the closest place at the given location.

browser position.address.postalCode always null

I noticed that in FF4 i can use geolocalisation object
position.address.postalCode to find the postalCode.
When testing on FF10 I noticed that position.address is always null, while I can still use position.coords without any problem to find longitude or latitude.
Can someone please tell me if there is simple way to find out postalCode in FF10 with position object?
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(findClosestAgencies);
}
function findClosestAgencies(position) {
alert("postalCode:" + position.address.postalCode);
alert("latitude:" + position.coords.latitude);
}
my code:
Thank you
According to the spec:
http://dev.w3.org/geo/api/spec-source.html#position_interface
Position is only required to have coordinates and timestamp. FF4 may have had some additional data, but its not guaranteed to be there since its not part of the spec. Try using the coordinates with an address finding service.
The address is only available when it's available; there's no guarantee that it will be non-null, in other words. It depends on how much information the browser can get.
If you can only get the lat/long, you might be able to fall back to using another geolocation web service. (Such a service is almost certainly also not guaranteed to return a postal address; if I'm using your website from a boat on a large lake, for example, I might have no meaningful postal address under any circumstances.)

Resources