Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Native Map object does not work on Android
Started by Divergent Monkey Jan 04 2019 09:26 AM

25 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

Google recently started to require having a map key to access the Google maps API. According to the docs, this is how it should look in config.lua:

license = {
        google = {
            key = "[my google iap key]",
            mapsKey = "[my google maps key]",
        }
    } 

"key" is for Google IAP and "mapsKey" is for the maps. However, I get an error message when running the app on Android. This is what Google support says:

 

 

It looks like you are having issues adding the API key to the JavaScript Map request, so it does not authenticate under your project. If you are not able to add an API key in your Map request, or you have an invalid character in your request (like a space or when URL encoded, it could be a plus sign (+), or any special character), or you accidentally added an extra character or deleted a portion of the key, you will have an error for invalid key. The error will result to a grey map with "Oops! ----" message.

 
Is there a way for you to log the full URL request that your application is sending?

 

Google support has confirmed the validity of my key and I have double checked that the key is entered correctly in config.lua. My questions:

 

  1. I have checked the NativeDisplayObjects sample app and it is the same thing there. Does it for for anyone else?
  2. How could I see the url that is sent from my device to google maps? I cannot find it in the logfile of the device...


[TOPIC: post.html]
#2

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,183 posts
  • Corona SDK

Did you put the string in quotes? It should be a string.

 

I didn't actually test it but I traced that key all the way to the URL. This is the URL being used:

 

'https://maps.googleapis.com/maps/api/js?v=3.9&sensor=false&key=' + googleApiKey


[TOPIC: post.html]
#3

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

Yes I put it in quotes in config.lua. Can you make the NativeDisplayObjects sample app work? Even if you have a google iap key in config.lua as well?



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

I looked at the source and we are certainly using "mapsKey" in config.lua in the application.license.google table.

 

If you're uncomfortable sharing your api key here, you can put together a simple sample project that adds a native.newMapView() to a simple app with your build.settings and config.lua and package that up and a zip file and email it to support@coronalabs.com and we can take a look at it.

 

Rob



[TOPIC: post.html]
#5

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,183 posts
  • Corona SDK

@divergent I get an error on mine but it is not the exact error that you mention.

 

1. Did you add a credit card to your account and turned on billing? Once you do that your "map loads per day" should be more than 1.

 

Attached File  2.png   32.12KB   0 downloads

 

2. Do you see any 200 responses on your console? Mine doesn't show anything but 200.

 

Attached File  here1.png   43.86KB   0 downloads



[TOPIC: post.html]
#6

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

@Rob: I have modified the NativeDisplayObjects to emulate the functionality in my app and emailed it ti the addrss you provided. 

 

@Agramonte: according to Google support, since my requests are not validated, no activity can be seen neither in my console or in theirs.



[TOPIC: post.html]
#7

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,183 posts
  • Corona SDK

@divergent I have never used the maps API until last night. All I did was create an account, add my credit card and added the maps key to the NativeDisplayObjects sample. Clicking on the maps button in that app brings up the map. As you can see in the graph I then tested it at 7, 8 and 9pm EST. I wanted to see if I can fix the other problem I found (but I couldn't).



[TOPIC: post.html]
#8

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

@agramonte: what Android version did you test this on? Any issues regarding credit card, billing etc would come after making a valid request but I am not even there yet...



[TOPIC: post.html]
#9

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,183 posts
  • Corona SDK

I tested on two devices.

 

1. An Android 9 phone. On this one, it throws an error after the map loads with my manual lat long. I think the map is trying to get the current location but doesn't have permission and the app doesn't prompt.

2. An Android 7.1.1 tablet. On this one, it throws a different error, but again it is after the map loads.

 

What version are you using? I can dig up some of my older phones. I don't have a 8.x device.

 

Edit: I think this is a rabbit hole you are going into with no end in sight. Even after you get past your current problem, I notice other problems that I am fairly sure are code related.


Edited by agramonte, 05 January 2019 - 09:06 AM.


[TOPIC: post.html]
#10

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

@agramonte: I was using version 8.0 when testing. If you want, I could send you the sample app that I sent to Corona support. You could then insert your google maps key instead of mine and see if that works or at least if you get the same error as I do. Let me know, and I can then send it as a private message to you here in your Corona account.



[TOPIC: post.html]
#11

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,183 posts
  • Corona SDK

Yes please send it to me. I'll test it out.



[TOPIC: post.html]
#12

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

Ok, I've sent it. Thanks!



[TOPIC: post.html]
#13

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,183 posts
  • Corona SDK

I couldn't get your code to work but I don't really understand it. I think you didn't send me all of it and if this is the same thing you sent to Corona they won't be able to help you.

local maptest = require("sampleUI.maptest") -- I am missing this file. Maptest is null.

then further down you call this:

maptest.create() -- this is null and you are calling this function from that file I don't have.

I erased everything you had except the first line and put my key in the config:

display.setStatusBar(display.HiddenStatusBar)
--local maptest = require("sampleUI.maptest")

local mapView = native.newMapView( display.contentCenterX, display.actualContentHeight/2, display.actualContentWidth, display.actualContentHeight )

mapView:setCenter( 37.331692, -122.030456 )

And here is the picture from my device:

 

Attached File  device-2019-01-05-153949.png   470.64KB   0 downloads



[TOPIC: post.html]
#14

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

The zip file submitted to support was complete. Once I added my license key, I was able to build with your mapsKey and the native.newMapView() came up and complained about an issue. I replaced the key with a key I use in a maps based app (I'm doing a Google JavaScript map in a webView because I'm overlaying weather radar on top), rebuilt and re-run your app and I got a map centered on where I live with no error.

 

So based on my results and Agramonte's results, this seems to be related to your key and not native.newMapView()

 

Rob



[TOPIC: post.html]
#15

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

@agramonte: there must be some kind of misunderstanding. The zip file I sent to Corona was exactly the same I sent to you but with my mapsKey removed. The file maptest.lue is in the folder SampleUI.  

 

@Rob: what was the issue that the Map view complained about? When I run it, I get no map at all. What Android version were you using? I don't get this... 



[TOPIC: post.html]
#16

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

@Rob: could you please try one more time with the zip file I sent (with my map key)? I have removed all restrictions from it in the Google dashboard, just curious if that changes anything for you.

 

UPDATE: I just found this in the Android logfile:

 

01-05 20:46:38.290 31943 31943 I chromium: [INFO:CONSOLE(50)] "Google Maps JavaScript API error: RefererNotAllowedMapError

12-30 20:46:38.290 31943 31943 I chromium: Your site URL to be authorized: __file_url__//data/user/0/[my package name]/cache/.system/resources/corona_map_view2.html", source: https://maps.googleapis.com/maps/api/js?v=3.9&sensor=false&key=[my map key] (50)

 

On the credentials page of the Google Cloud Platform, you can apply restrictions. I had my restrictions set to "Android apps", but I now understand that a Corona app is not an "Android app" in this sense since it uses a web view for displaying the map. Therefore, I must instead apply restrictions for "HTTP referrers (website)".

 

Since your key worked in my app you either have no restrictions on your key, or you have entered a "HTTP referrers (website)" restriction. Can you please confirm that? If so, is the URL that you entered really " __file_url__//data/user/0/[my package name]/cache/.system/resources/corona_map_view2.html"?



[TOPIC: post.html]
#17

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

It now works with your Maps API key

 

Rob



[TOPIC: post.html]
#18

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

Ok, great, then it was the applied restrictions...

 

One last question: what did you enter under "HTTP referrers (website)"? Was it " __file_url__//data/user/0/[my package name]/cache/.system/resources/corona_map_view2.html" like it said in the logfile I quoted or was on some other format?



[TOPIC: post.html]
#19

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

I don't remember entering anything.



[TOPIC: post.html]
#20

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

If so, your key is "unrestricted" and could potentially be used by someone else. At least according to the instructions at the google cloud platform website where the keys are handled. Since Corona apps do not have a url request per se even though the request comes from a web view, I will have to let google support help me on what url to enter "HTTP referrers (website)".

 

@Rob & agramonte: thank you so much for your help, I really appreciate it!  :)



[TOPIC: post.html]
#21

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

@Rob:

 

Just got this from google support regarding the logfile I sent them:

 

 

The "RetiredVersion" means that the application is making a request to a version of Google Maps JavaScript API that is already retired. A way to fix this is to replace the version in the request URL. The request URL can also be found in the logs that you have sent:

 
 
The v=3.9 is not an updated version. But, this has to be fixed by the Corona team, since they are the ones who set that up.
 
Another error says "SensorNotRequired". This means that the request URL is also using a deprecated parameter which is "sensor". This parameter is no longer working and should no longer be used. This can also be fixed only by the the Corona Team.

 

In other words: the request that Corona is making to Google Maps uses partly deprecated or non-supported parameters. This has got nothing to do with my error, this is the same for everyone using Corona.

 

Could you please forward this to your engineers?

 

UPDATE:

In case anyone wonders, this is the url that should be filled out with the "HTTP referrers (web sites)" choice:

 

__file_url__//data/user/0/[your package name]/cache/.system/resources/corona_map_view2.html

 

This could be a bit tricky if Corona ever decides to change the name of the html file. In that case, the request will not be valid and no map will be displayed...



[TOPIC: post.html]
#22

runislabs

[GLOBAL: userInfoPane.html]
runislabs
  • Observer

  • 5 posts
  • Corona SDK

I would suggest trying https://marketplace.coronalabs.com/corona-plugins/map-plugin , it's easy to develop using Corona Simulator.



[TOPIC: post.html]
#23

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

Thanks or the tip! Just curious: is the map displayed in a web view? Who is the content provider, Google, Apple or someone else?



[TOPIC: post.html]
#24

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,925 posts
  • Enterprise

@Divergent Monkey, I don't believe either of those URL parameters are causing an error. I agree that they are old and not doing anything, but they shouldn't be causing any harm either.

 

I've raised it with engineering, but I'm not sure what the priority will be on fixing it. Since we've gone to an open source model, we also are now using GitHub issues to track these types of bugs. Can I get you to visit:  https://github.com/coronalabs/corona/issues

 

And file an issue for this. Perhaps if we can't get to it in a timely fashion, a community developer who wants to contribute to Corona can look into it.

 

Rob



[TOPIC: post.html]
#25

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 332 posts
  • Corona SDK

@Rob:

 

True, they don't cause any problems (confirmed by Google support) but if possible, they should be fixed just for the sake of keeping Corona up-to-date. I have creted an issue at the GitHub page. Thanks!




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]