GEO-Location with mobile phone and google maps api - google-maps-api-3

I have been trying to create a mobile application which will search my own MySQL database which has stored information (lat, lng, business name's) about businesses.
Here is a step by step guide on how I am wanting it to work.
1). The user will manually input a postcode
2). PHP (laravel) will process the request
3). The Google Maps API will use the Lat,
Lngs I have stored in my database and display the location closest to the postcode which has been entered.
4). Display the results on the page
I am using PhoneGap to create the mobile application and for the PHP framework I am using Laravel.

My approach will be to cache the postal codes and lat,lng on to a table. so your requests will be faster.
what you need to do is get the postal code from the user and send it to the google api to get the lat long. then use those values to search the db.
This tutorial on google might help when geting closest the businesses from the db. https://developers.google.com/maps/articles/phpsqlajax_v3

Related

How to apply API key to Google Maps Tile server URL?

I want to use Google Maps Tile server URL inside an application.
I'm using the URL
https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga
and it is working fine.
The problem is that I'm not sure how to use my Google Cloud API key for this URL.
I tried adding the API key at the end of the URL:
https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga&key=[MY_KEY]
but I don't see any activity on "Maps JavaScript API" in my Google cloud console. Meaning that the API Key is not being used.
Does this URL need an API Key?
It's working without the Key for now, but I'm afraid it may not work in the long run or it may be illegal to use it without the Key.
Ok, So I spend some time on this and found some solutions for directly using Map Tile Server URL (without any coding required). Here is a summary:
Google Maps:
The URL https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga currently works, but it is illegal to use as it violates Google Maps TOS Section 3.2.4a https://cloud.google.com/maps-platform/terms/#3-license. because it doesn't use an API Key.
There was a service called Google Maps Tile API, but it has discontinued since September 2019 (the API key need to be whitelisted to be able to use this service, and they don't do it anymore since Sep).
So it seems for now there is no easy and simple way to get Tile Server URL from Google Maps.
Bing Maps:
The URL is in the form http://ecn.{subdomain}.tiles.virtualearth.net/tiles/r{quadkey}.jpeg?g=129 where quadkey is a compact representation of variables x, y and z. So doesn't work directly in applications that require URL's that have x,y,z variables.
Azure Maps:
The URL is in the form https://atlas.microsoft.com/map/tile?subscription-key=***&api-version=2.0&tilesetId=microsoft.imagery&zoom={z}&x={x}&y={y}. For different settings see here. The shortcoming of this approach is that currently it cannot be set to show hybrid maps (satellite + street and city names).
MapBox:
The URL is in the form https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/256/{z}/{x}/{y}?access_token=***. You can set the style of the map (currently set to satellite-streets-v11) by choosing the desired value from here and replacing in the URL.
If you want to directly access map tiles, consider Azure Maps. They don't have the restriction that Google Maps has. It's also cheaper. Here are some samples that directly access the tile server: https://azuremapscodesamples.azurewebsites.net/index.html#Third-Party-Map-Controls
Here are some other useful resources:
https://azure.com/maps
https://learn.microsoft.com/en-us/azure/azure-maps/
https://learn.microsoft.com/en-us/rest/api/maps/render/getmaptile

How do i tell Openrefine to fetch some data trough the google and facebook API (Grel)

I have a list of around 500 foundations and companies and i need to fetch more data like address, description, lat long, email or phone number, from the google and FB APIs I have found something more or less like this, but it won't work in OpenRefine, i need some help please.
I think it is possible to do beacause there is an addon called spotlight for spreadsheets that is able to fetch Google URLs and Lat Long https://www.youtube.com/watch?v=Vj1v3QfyrgA&feature=youtu.be
https://maps.googleapis.com/maps/api/place/findplacefromtext/output?parameters/json?input=value&inputtype=textquery&fields=photos,formatted_address,name,rating,email,geometry&key=YOURKEY
I have created the FB and Google places and google staic map API already. I have tried different queries, but it won't work unless it is in GREL
value.parseJson().geonames[0].lng
value.parseJson().geonames[0].geonameId
value.parseJson().geonames[0].lat
From the error "This API project is not authorized to use this API" the first thing to check is that you have enabled the Places and/or Geocoding API in the Google Developer console, and you have setup an API Key and that it is showing as a credential for the Places API and/or the Geocoding API
Next step, take OpenRefine out of the equation and check you can get a simple API call working in your browser - using one of the Google Places API examples:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Museum%20of%20Contemporary%20Art%20Australia&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry&key=<INSERT YOUR API KEY HERE>
If that gives you the same error, you know the issue is not with OpenRefine.
If you are still having problems in OpenRefine make sure you are creating URLs in OpenRefine that are valid for the appropriate Google API based on the documentation for that API and that you are using the correct API key.

Getting device location using Dialogflow-fulfillment, not using Google Actions

What I am trying to do here is, suppose a hospital which provides certain facility has several centres(locations) in the country. Now when the user requests for such hospital, the bot should be able to output him the location of the nearby hospital. I do have the list of all such hospitals in Firebase Real-Time Database with respective longitude and latitude.
My appraoch is to get the user's location and compare it with the available locations in the database for a nearby location?
On this link, It is discussed how to get the location of the user using "Google Actions". I want to do the same thing (getting the precise location of the user) using dialogflow-fulfullment (WebhookClient({ request, response });) from Inline editor on Dialogflow so that I can use Real-Time Database of Firebase.
My motive is to make it inclusive to most of other platforms as well. Whereas, Google Actions are only valid for Google Assistant.
PS: Any suggestion on this would be highly appreciable. I would be happy to put more clarification if required.
Getting the user's permission for location is only a feature of Actions on Google and not Dialogflow itself. You could ask the user to provide their current location manually, but would face difficulty doing it automatically otherwise.
Spoke with Dialogflow Support Team
Mentioned link in the email: https://developers.google.com/actions/reference/rest/Shared.Types/Permission
You can use Actions on Google Helpers to retrieve the user location. You can follow this link for documentation: https://developers.google.com/actions/assistant/helpers#user_information

How to query Google Analytics using Javascript

We're want to query Google Analytics remotely, to retrieve (and display) a list of most popular pages (in a certain period) on a website. The examples I've looked at, for querying Analytics using Javascript, seem to require an user/person to login. Is this correct? Is there a way of skipping this step, and querying Analtyics unattended?
Thanks,
Toby
No. the data inside Google Analytics is potentially strategic and the tool doesn't provide non-logged in access at any time.
In order to do what you want the best approach is probably to query the data using your credentials on the server side and store the data on a database. Run that again every night or so.
Then you just query the database and generate the count to display on the frontend.
You don't want to do that on javascript because you would be exposing your credentials to anyone visiting your site to query all your Google Analytics data.

How can I generate a GA tracking code programmatically?

How to generate Google Analytics tracking code programmatic-ally?
I am new to Google Analytics API, can someone please help
It is NOT possible to create new Google Analytics accounts or profiles programmatically using the existing APIs.
There are two APIs available, the Data Export API and the Management API. However, they are bot read-only.
With the Google Analytics Data Export API, you can develop client applications to request data from an existing Analytics profile for an authorized user, and refine the results of the request using query parameters. Currently, the Data Export API supports read-only access to your Google Analytics data.
Currently, the Management API supports read-only access to five components of the Google Analytics Management system: Account data,Profile data, Web property data, Goal data, Advanced segments
Seems like it's finally possible in 2021 with alpha api.
https://developers.google.com/analytics/devguides/config/admin/v1/rest/v1alpha/properties/create#authorization-scopes
It's not currently possible to create Google Analytics accounts automatically at the moment but generating the tracking code is possible.
The only real variation between the tracking code generated each time you create a profile for a new domain is the web property ID. This is in the format UA-XXXXXXX-X. Each X is a number - the first 7 numbers are the account number and the number after the last dash relates to each web property set up for the account.
You can use the accounts feed of the API to get a list of accounts and their profiles. If an account only has one profile then it's possible to use the web property ID of it to automatically generate the tracking code. However, if there's multiple web properties then you would need a way to decide which one to use (present the user with a selection list etc).

Resources