Getting Google Maps API warning: in ACF Google Map Wordpress - advanced-custom-fields

I am Getting Google Maps API warning: in ACF googlemap type field Wordpress BACKEND when i am going to enter address in page, I know this i have to add google map api key but where do i have to?
Map doesn't load when i enter address...

You have to add this code to functions.php:
Change xxx with you api-key.
function my_acf_google_map_api( $api ){
$api['key'] = 'xxx';
return $api;
}
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
Hope it helps! :)

From https://www.advancedcustomfields.com/resources/google-map/ if there still error, the error on developers console should have an explanation and a link how to fix it
// Method 1: Filter.
function my_acf_google_map_api( $api ){
$api['key'] = 'xxx';
return $api;
}
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
// Method 2: Setting.
function my_acf_init() {
acf_update_setting('google_api_key', 'xxx');
}
add_action('acf/init', 'my_acf_init');

Related

Can't import geojson value as string in google maps with firebase web

So, I set up my firebase to communicate with my web app which uses google maps api and my goal is this: When a user draws a shape on the map(polygon, linestring), I want to send the geoJson value of it to the firebase(currently sending it as a String), and then retrieve it back so it appears on the map for everyone(since it's getting synced from the firebase database). My problem is that when I try to retrieve the geoJson data back and add it on google maps, at the line map.data.addGeoJson(geoJsonString);(geoJsonString = geoJson value that is stored in firebase) I get an error saying:
Uncaught Jb {message: "not a Feature or FeatureCollection", name: "InvalidValueError", stack: "Error↵ at new Jb (https://maps.googleapis.com/m…tatic.com/firebasejs/4.13.0/firebase.js:1:278304)"}
For some reason google maps api doesnt accept the geoJson value even though console.log(geoJsonString); returns a valid geoJson value (checked at http://geojsonlint.com/)
Now the strange part is that if I try to import the same geoJson value manually(storing the geoJson value in a var and then map.data.addGeoJson(geoJsonString);) it works just fine.
This function syncs firebase with the web app
function gotData(data){
paths = data.val();
if(paths == null){
console.log("firebase null");
alert('Database is empty! Try adding some paths.');
}
else{
var keys = Object.keys(paths);
for(var i = 0; i < keys.length; i++){
var k = keys[i];
var geoJsonString = paths[k].geoJsonString;
console.log(geoJsonString);
map.data.addGeoJson(geoJsonString);
}
}
}
This function updates and pushes data in firebase
function updateData(){
data = {
geoJsonString: geoJsonOutput.value
}
ref = database.ref('firebasePaths');
ref.push(data);
}
In this function(which is used to store geoJson values locally in a file), I call updateData function), after a new path is drawn on the map
// Refresh different components from other components.
function refreshGeoJsonFromData() {
map.data.toGeoJson(function(geoJson) {
geoJsonOutput.value = JSON.stringify(geoJson);
updateData();
refreshDownloadLinkFromGeoJson();
});
}
Example of my firebase that contains 2 random geoJson
I can't trace where the problem is. Any ideas?
Update: I managed to fix this issue by parsing the string with JSON.parse("retrieved string from firebase"), saving it to a variable and then adding it to the map with map.data.addgeoJson(parsed variable).
We still have not faced that issue, however, we are aware of it.
Our intended solution is to use GeoFire: An open-source library for the Firebase Realtime Database that adds support for geospatial querying.
You can find the library description in here:
https://firebase.google.com/docs/libraries/
For the Web supported library:
https://github.com/firebase/geofire-js

multiple permisions scope google fit api integration

I am integrating Google fit API in an open source project am working on where I allow the user to login with the Google account credentials and through the user consent process. I have this error when I try to pass in additional scope permissions on the sign in Uri. I am not sure if it's a problem with my URL encoding because I am sure the API expects an array of scope urls. Is it possible to put multiple permissions in one oauth flow in Google fit API integration?
The first URL is working fine but the others get an error instead of redirecting.
https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://accounts.google.com/o/oauth2/auth?access_type%3Doffline%26as%3D43045f60390ad399%26approval_prompt%3Dforce%26scope%3Dhttps://www.googleapis.com/auth/fitness.activity.read%26response_type%3Dcode%26redirect_uri%3Dhttps://developers.google.com/oauthplayground%26client_id%3D1086862838918-d6epsnkqrid4tu786geh3nfugpga2ii5.apps.googleusercontent.com%26from_login%3D1&oauth=1&sarp=1&scc=1
https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://accounts.google.com/o/oauth2/auth?access_type%3Doffline%26as%3D43045f60390ad399%26approval_prompt%3Dforce%26scope%3D%5B%22https://www.googleapis.com/auth/fitness.activity.read%22%2%22https://www.googleapis.com/auth/fitness.activity.write%26response_type%3Dcode%22%5D%26redirect_uri%3Dhttps://developers.google.com/oauthplayground%26client_id%3D1086862838918-d6epsnkqrid4tu786geh3nfugpga2ii5.apps.googleusercontent.com%26from_login%3D1&oauth=1&sarp=1&scc=1
Have you check the Getting Started on Android documentation of Google? Here is their sample code for adding scope:
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addConnectionCallbacks(this)
.build()
You can try using addApi() and addScope() to get permission of Scope to be used.
From this tutorial:Google Fit for Android: Sessions API, it is possible to add multiple permission scope for Google Fit API integration.
Here is their sample code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SESSIONS_API)
.addApi(Fitness.HISTORY_API)
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE))
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addConnectionCallbacks(this)
.enableAutoManage(this, 0, this)
.build();
}
EDIT:
For web I think you can use Requesting additional permissions via OAuth 2.0
auth2 = gapi.auth2.init({
client_id: 'CLIENT_ID.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin', /** Default value **/
scope: 'profile' }); /** Base scope **/
Wherever additional scopes are needed, request them by constructing an options builder with the scopes you want to add and then calling user.grant({scope: [OPTIONS BUILDER]}).then(successFunction, failFunction);:
var options = new gapi.auth2.SigninOptionsBuilder(
{'scope': 'email https://www.googleapis.com/auth/drive'});
googleUser = auth2.currentUser.get();
googleUser.grant(options).then(
function(success){
console.log(JSON.stringify({message: "success", value: success}));
},
function(fail){
alert(JSON.stringify({message: "fail", value: fail}));
});
Add this to you node.js then here is the list of scope for Google FIT web
HTH

Replace Video Resource with VIMEO API

I am trying to replace existing video on VIMEO with
advanced api from : https://github.com/vimeo/vimeo.php#replace-videos-from-the-server.
The code is:
$vimeo = new \Vimeo\Vimeo('xxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxx');
$vimeo->setToken("xxxxxxxxxxxxxxx");
$video_id_on_vimeo = 123456; // not real id
$vimeo->replace("/videos/" . $video_id_on_vimeo, $path_to_file, false);
However it throws me an error "Unable to get an upload ticket.[The requested user could not be found]'
All other commands do work. I am using OAUTH 2 and scopes configured for using apis are:
public private purchased create edit delete interact upload.
in order to run example, just execute POST request to http://panels.veedi.com/api/video/test
Vimeo development team fixed the bug.
Now everything is working. In addition in API description of replacement process, they have mistake.
Instead of:
$response = $lib->upload('/videos/12345', '/home/aaron/Downloads/ada.mp4', false);
You should use:
$response = $lib->replace('/videos/12345', '/home/aaron/Downloads/ada.mp4', false);

How to determine if address doesn't exists in Google Maps Api v3

Hi I'm trying to find out if an address exists in a City+Province+Country using google's maps API v3 geocoding webservice. I've seen that Google always returns something. For example, if I try to find an existing address: "Colon 100, Córdoba, Córdoba, Argentina" using: http://maps.googleapis.com/maps/api/geocode/json?address=Colon%20100%20,C%C3%B3rdoba,C%C3%B3rdoba,Argentina&sensor=false I get a something. But when I try to find and non existing address like, "nonexistingaddres 2, Córdoba, Córdoba, Argentina" using : http://maps.googleapis.com/maps/api/geocode/json?address=nonexistingaddress%20100,C%C3%B3rdoba,C%C3%B3rdoba,Argentina&sensor=false I also get a result. I'dont know how to find out if "nonexisting" street exists or not by just analyzing the google's response.
Thanks in advance, Mono.
I know this question is old, but I figured I'd answer it anyway for people still looking. The best way to handle this in my experience is to look at the API response. I don't use Google Maps for address verification, just for finding coordinates, but I need to fail properly if the address someone has provided isn't valid (at least as far as Google is concerned), since it won't return usable latitude/longitude for my app to consume.
In PHP, I do something like this:
public static function latlong($location) {
if ($location!='') {
try {
$json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($location));
$parsedjson = json_decode($json, true);
if (key_exists(0,$parsedjson['results'])) {
$lat_long_array = $parsedjson['results'][0]['geometry']['location'];
return $lat_long_array;
} else {
return false;
}
} catch (Exception $e) {
//echo 'Caught exception: ', $e->getMessage(), "\n";
return false;
}
}
}
Hope that helps any Googlers who end up here.
The Google Maps API v3 geocoder is not an address validator. Its purpose is to find the best coordinates for a given (postal) address.
That doesn't stop people from trying to use it

Problem to pass a kml file to Google Earth using geoxml3 class and ProjectedOverlay class

i am trying to build a google earth view showing cities, but i stuck with the kml parser geoxml3. I have a javascript building a google map at first showing the locations i want. this works fine. I call the function from a php script providing it an address and kml file reference from database. The function builds the map, sets a flag 'map_finished' as a control flag when all ran fine and calls the build google earth view function.
// Get maps and earth from google
google.load( 'maps', '2.s', {'other_params': 'sensor=true'} );
google.load( 'earth', '1' );
//Google Earth Initializer
function initObjectEarth() {
// Check if Google Earth plugin is installed
if( gm_loaded ) {
this.ge_plugin_installed = google.earth.isInstalled();
if( this.ge_plugin_installed ) {
google.earth.createInstance( 'inmap', geSuccessCallback, geFailureCallback );
ge_loaded = true;
} else {
alert( 'Your Browser has not yet installed the Google Earth plugin.
We recommend installing it to use all features!' );
return false;
}
}
}
// Success handler
function geSuccessCallback( object ) {
this.ge = object;
this.ge.getWindow().setVisibility( true );
this.kmlParser = new geoXML3.parser();
}
// Error handler
function geFailureCallback( object ) {
alert( 'Error: ' + object );
}
The geoxml parser uses the ProjectedOverlay class. Both libraries are loaded into document head. When the parser is getting instatiated it requests a ProjectedOverlay instance. This class throws a
Error: **google.maps is undefined**
error in firebug for the following statement
ProjectedOverlay.prototype = new google.maps.OverlayView();
In my script file i have declared vars including
var gm //for google map
var ge //for google earth
gm is set in the function that builds the google map.
I wonder how to fix this issue. I tried the getProjection() thing i found in web as well as
ProjectedOverlay.prototype = new google.maps.OverlayView().prototype;
with no success. This topic is absolutely new to me and i cannot figure out how to fix it neither from the documentation of OverlayView nor from google search.
What did i forget or do wrong?
The call to the geoXML3 constructor is wrong, you must pass the google.maps object as a parameter (...hence the "google.maps is undefined" error).
this.kmlParser = new geoXML3.parser({map: gm}); // gm for google map