Xamarin Forms Google Maps dynamic Api Key [duplicate] - google-maps

I have a use-case in my android app that users of my application have to give API key so that they can use the map.
but I see that I have to give the API key in the manifest file. which I can't edit at the runtime.
is there any other ways to give the map API key dynamically to the google map (I'm using MapView) or any ways to change the meta-data values dynamically

Unfortunately, this does not seem possible at all.
Google documentation
https://developers.google.com/maps/documentation/android-sdk/get-api-key#add_key strictly talks about the manifest and how to add the key to the local.properties:
Open the local.properties in your project level directory, and then add the following code. Replace YOUR_API_KEY with your API key.
MAPS_API_KEY=YOUR_API_KEY
and then referencing it from the Manifest:
In your AndroidManifest.xml file, go to com.google.android.geo.API_KEY and update the android:value attribute as follows:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
Deprecated and since removed constructor
Apparently, a long time ago there was indeed a way of injecting the key when instantiating the MapView object manually (i.e. not with a layout xml): https://stackoverflow.com/a/11739039
mMapView = new MapView(this, mapApiKey);
However, this constructor was removed since and you cannot give the API key anymore:
https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/MapView?hl=en#public-constructor-summary
MapView(Context context)
MapView(Context context, AttributeSet attrs)
MapView(Context context, AttributeSet attrs, int defStyle)
MapView(Context context, GoogleMapOptions options)

Related

How to create a new element in visualcomposer.io API ( visual composer) (not a wpbakery)

How to explore this API https://visualcomposer.io/docs/api/
I have installed this plugin https://github.com/VisualComposer/vcwb-demo-element-example-plugin. But when I am trying to add any new attribute into setting.json it not reflect in the UI.
You have to add this attribute's key to the object - 'editFormTab1'. For example, there is an attribute - 'metaCustomId' and it has been added to the list in object - 'editFormTab1'.

Google compute project-wide SSH keys with jclouds

I'm trying to launch google compute instances from java code using jclouds. It's mostly working, however I'd like to use the project-wide SSH key I've defined instead of having jclouds generate a new user/key credential.
According to the README here - https://github.com/apache/jclouds/tree/master/providers/google-compute-engine:
For an instance to be ssable one of the following must happen: 1 - the project's metadata has an adequately built "sshKeys" entry and a corresponding private key is provided in GoogleComputeEngineTemplateOptions when createNodesInGroup is called. 2 - an instance of GoogleComputeEngineTemplateOptions with an adequate public and private key is provided.
I'm trying to do 1) above. I've correctly configured the project's metadata (I can use it to connect to manually-created instances that don't have jclouds-generated credentials), but I can't work out how to provide that key to GoogleComputeEngineTemplateOptions?
Neither
GoogleComputeEngineTemplateOptions.Builder.installPrivateKey(String key) or GoogleComputeEngineTemplateOptions.Builder.overrideLoginPrivateKey(String key) seem to work.
The documentation is pretty sparse - anyone know how to do it?
jclouds will create a key by default if you don't provide one. You could use the following to provide your auth private key and tell jclouds not to generate a new one:
TemplateOptions opts = computeService.templateOptions()
.as(GoogleComputeEngineTemplateOptions.class)
.overrideLoginPrivateKey(privateKey)
.autoCreateKeyPair(false);

nativescript-google-maps-sdk use native calls to style the map

I successfully integrated a google map at my angular2+nativescript project. Everything I needed from the typescript definition file is working for me.
However, I wanted to play around with the styling of the map. AFAIK, I have to use native calls to the map, as the method setMapStyle() is not in the typescript definition.
I thought I could use the gMap property to access the native object and call the method. But I fail in setting up the right parameter as requested in google docs (https://developers.google.com/maps/documentation/android-api/styling) as I dont know how to create a MapStyleOptions object. The type is unknown.
Anyone tried or succeeded in this task yet and want to share some hints? How would you access native GoogleMap?
NativeScript allows you to access all public API of plugins used in the app, therefore you should be able to make native calls to the Map API as per the documentation at nativescript.org
If you want to create a MapStyleOptions object for example, you'd write
var MapStyleOptions : any = com.google.android.gms.maps.model.MapStyleOptions;
var mapStyle : any = new MapStyleOptions({"..":".."});
or just var mapStyle = new com.google.android.gms.maps.model.MapStyleOptions({"..":".."});
When TypeScript complains about com.google... not being recognized, you can either define it as any or import some ready to use typings.
Good luck!

What are the parameters of map.setCenter?

I can't reliably find a single documentation of the function where a second number is passed to it as a parameter. I have a code (from a book) that reads :
map.setCenter(loc, 20);
where loc is a google.maps.LatLng object. However, what is the number (20) fed to the function? What does it do?
That is (probably, since you don't provide context) from the deprecated and turned off Google Maps JavaScript API v2.
It allowed the center and zoom to be set in a single operation.
From the documentation (on archive.org, since it was turned off May 2013 and the official documentation has been removed)
setCenter(center:GLatLng, zoom?:Number, type?:GMapType) | None
Sets the map view to the given center. Optionally, also sets zoom level and map type. The map type must be known to the map. See the constructor, and the method addMapType(). This method must be called first after construction to set the initial state of the map. It is an error to call operations on a newly constructed GMap2 object until after this function is invoked.
(note: there is a wrapper for v2 that allows some of the v2 functionality to continue to work, but if that breaks, don't expect it to be fixed...)
related issue in the issue tracker #10333

Web API: 'Global' filter not working (ExceptionFilter)

I implemented the exception filter like here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling
And registered it globally, like microsoft or stackoverflow-users ( How to add global ASP.Net Web Api Filters? ) explained.
public static void RegisterWebApiFilters(System.Web.Http.Filters.GlobalFilterCollection filters)
{
//other filters
filters.Add(new MyExceptionFilter());
}
But if I throw an exception, my method is not called.
My exception-handling method is called only if I add the attribute [MyExceptionFilter] to the controller-method, but I hoped I can avoid that for all methods by registering the filter globally.
I tried to set a order for the filters, but this had no effect.
Edit: I have noticed, that in the new Wep Api RC the method is called "RegisterGlobalFilters" and this seems to be the MVC filter collection.
If I call
GlobalConfiguration.Configuration.Filters.Add(new MyExceptionFilter());
it works. This is the collection for the Web Api.
Looks like I have to build my own "FilterConfig" class for the web api...
Like I mentioned in my question: There are different filter collections. One for MVC and one for the web api.
If you want to add the filter to the web api, add this line of code to the global.asax
GlobalConfiguration.Configuration.Filters.Add(new MyExceptionFilter());