Store Locator API + Geolocation - google-maps-api-3

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.

Related

How to create tracking pixel with Google Analytics for 3rd party site?

We need to track conversions that happen on a 3rd party site. The only thing we can place on that site is an image pixel and maybe some JS logic for when to fire it.
I know it is possible to fire a conversion using the Measurement Protocol: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#visitor
Ideally, I'd just give the 3rd party an IMG url and that would be it. The problem is the CID (unique client id).
I can try passing the CID from our site to the 3rd party via URL parameter. However, there are many cases where its not available (e.g., IMG pixcel will be in an email, the goal URL is on printed literature) or the 3rd party is not willing to go through the hassle. Is it best practice to pass this CID in this way?
I can try generating a CID, but I can't find a dead simple way of doing that e.g., var CID = generateCID(). The 3rd party site has its own GA on the page. Can I just take their Google Analytics CID and use it in the image pixel URL?
What the best way to do this? Thank you!
If the 3rd-party site has analytics.js already running then using that client ID is probably best. You can get it by doing the following:
var cid;
ga(function(tracker) {
cid = tracker.get('clientId'));
});
If analytics.js is not running, or if you can't access the ga variable for some reason, you can just generate the client ID randomly. This is approximately what Google does. It's a random 31-bit integer with the current date string appended:
var cid = Math.floor(Math.random() * 0x7FFFFFFF) + "." +
Math.floor(Date.now() / 1000);
Only to complement #Philip Walton excellent answer, Google Analytics expects a random UUID (version 4) as the Client ID, according to the official Documentation.
Client ID
Required for all hit types.
This anonymously identifies a particular user, device, or browser
instance. For the web, this is generally stored as a first-party
cookie with a two-year expiration. For mobile apps, this is randomly
generated for each particular instance of an application install. The
value of this field should be a random UUID (version 4) as described
in http://www.ietf.org/rfc/rfc4122.txt
#broofa provided a simple way to generate a RFC4122-compliant UUID in JavaScript here. Quoting it here for the sake of completeness:
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});

How to properly use Google Maps API? [duplicate]

This question already has an answer here:
google.maps.Geocoder.geocode() geometry.location lat/lng property names change frequently
(1 answer)
Closed 9 years ago.
I found out, while using Google Maps API, the results change from time to time. By change I mean the response object. Basically I'm querying Google Maps to get a list of places based on user input (also using jQueryUI auto complete). I'm trying to correctly fetch the coordinates which get returned from Google Maps API but the properties containing the exact|approximate coordinates seem to change from time to time.
For example: in earlier days I was able to get coordinates like item.geocode.geometry.location.Ya and item.geocode.geometry.location.Za. Then my search form broke because Google changed it to item.geometry.location.mb and item.geometry.location.nb.
Any suggestions on how to implement this the correct, and stable way?
Never use undocumented properties of a Maps API object like the ones you found. Those will change wildly whenever the Maps API is revised.
Instead, use only documented methods and properties.
Your item.geocode.geometry.location is a LatLng, so you can call its .lat() and .lng() methods:
var location = item.geocode.geometry.location;
var lat = location.lat();
var lng = location.lng();

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.

How to get `latitude` and `longitude` for an address? Google Maps

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.

Resources