문제

I want to set google mapView API key in my java code, not in xml

many answers in stackoverflow say this can be achieved by using "new MapView(Context, API string)"

but there's no such a "MapView(Context, String)" method

all four constructors for mapview are:

MapView(Context)

MapView(Context, AttributeSet)

MapView(Context, AttributeSet, int)

MapView(Context, GoogleMapOptions)

I'm using the latest Google Play services lib (r14), Google Map View v2

the reason I must set API key dynamiclly is that my company is worried about if the key is unavailable some day, the program will not be able to show the google map. so we write the key in a text file, and every time the program starts, it will read a new text file from server. So if the previous key is unavailable some day(for example, google stop the free key service and demand all customers to pay for a commercial key), we can change the text file in server and all our program will get the new key and runs fine.

any ideas? Thanks in advance.

도움이 되었습니까?

해결책

Again, AFAIK, this is not possible.

Moreover, the argument for why your company wants to do this is unrealistic IMHO. It is unlikely, in the scenarios that you describe, that replacing a key alone would have any effect. Rather, IMHO, it is far more likely that you would need to update the entire app, to integrate some new version of the Play Services SDK, perhaps in addition to replacing the key.

So, leave the key in the manifest, since you have no choice, and make sure that the company is in position to update its app as needed, whether for these sorts of Maps V2 disaster scenarios, or simply to improve the app.

다른 팁

According to the post here

How to use MapView in android using google map V2?

It seems like you will need to define it first in your xml

which it makes sense to define it in xml using the google library first and then use this link for documentation

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapView

hope this help

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top