dpdearing / android-gps-emulator

A Google Maps-based tool for simulating the GPS location of the Android emulator
Apache License 2.0
214 stars 50 forks source link

Google Maps API error: MissingKeyMapError #18

Closed devthejo closed 5 years ago

devthejo commented 7 years ago

Hello,

I'm unable to display map and the console output give me:

Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

Is there a way to specify a google maps api key ?

dpdearing commented 7 years ago

I can't reproduce the error with a fresh download of the war file. Are you running from the war or the source code?

No API key should be needed if running on localhost. Otherwise you will need to create an API key and update the code yourself. See https://developers.google.com/maps/documentation/javascript/get-api-key

An API key can be added when loading the Maps API script at https://github.com/dpdearing/android-gps-emulator/blob/359757a45aff3b0154d6dfb8e735491fcf7b01cf/src/main/webapp/gpsemulator/index.html#L110

thiagotalma commented 6 years ago

Same here...

dpdearing commented 6 years ago

@thiagotalma Can you give more details? Are you running on localhost?

thiagotalma commented 6 years ago

@dpdearing I was able to understand that the problem only occurs when the default port is changed.

When access is through localhost:8080 I have no problem with the key.

It is worth highlighting this in the documentation.

Taking advantage of the contact, could you clarify a question, please? Does this only work in emulators? Can not run using adb via USB on a device?

panaceya commented 6 years ago

I`m have also this problem.

Google map reqiured API key.

Neomeister2077 commented 6 years ago

Hi I seem to be having the same problem as the others, I personally am using localhost with the default port. There is no issue with the program authenticating to the emu and establishing a telnet connection. However when I load the web ui this (1) message appears from google, when clicking the "do you own this website" link it takes me to this page: https://developers.google.com/maps/documentation/javascript/error-messages?utm_source=maps_js&utm_medium=degraded&utm_campaign=keyless#api-key-and-billing-errors

Please advise.

(1) https://imgur.com/a/yLb6XG4

dpdearing commented 6 years ago

@panaceya and @Neomeister2077, do you see the same behavior as @thiagotalma about only having a problem when using a non-default port? (https://github.com/dpdearing/android-gps-emulator/issues/18#issuecomment-382003535)

In that case you may need to set your own API Key as I noted in https://github.com/dpdearing/android-gps-emulator/issues/18#issuecomment-333923521, or maybe Google changed something in the API that requires an API Key for everyone.

It's open source and I don't have a convenient configuration for testing this out, but feel free to submit a solution if you find one!

NgSekLong commented 5 years ago

or maybe Google changed something in the API that requires an API Key for everyone.

Yup, Google Map with no API key is not permitted anymore, -1 to Google.

So, how to fix?

I am not submitting a PR cause I am lazy to fix it, however you can fix it by:

  1. Editing the file in src/main/webapp/gpsemulator/index.html
  2. Change the map js from <script src="https://maps.googleapis.com/maps/api/js" async defer></script> to <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>
  3. Do the usual stuff (command line do mvn ... and java ...)

But I don't want to create a google map key D:

Here my google map key :P AIzaSyBqPKkQya1l2z combine above below sb0vFGysIOxcz6udDOoCg

I have restricted the above to only work on the following websites:

http://localhost:8888/*
http://127.0.0.1:8888/*

Still, be gentle when using my key D: Cheers for the great software!

dpdearing commented 5 years ago

Thanks @NgSekLong! I've been playing around with a way to store the API key in a local text file so that it's easier to create drop in each user's own key, but that's still kind of a hassle. Just dropping in a key with limitations as you suggest is probably the easiest solution in the short term.