Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by jainam · Dec 30, 2013 at 12:19 PM · apigoogleplaces

"REQUEST_DENIED" with Google Places API

Hello Everyone!

I am trying to use google places api in my unity project and followed all the steps mentioned here. Following is my C# code,

 #define ANDROID
 using UnityEngine;
 using System.Collections;
 using System.Timers;
 using SimpleJSON;
 
 public class Places : MonoBehaviour
 {
     static int Neversleep;
     LocationInfo currentGPSPosition;
     string gpsString;
     public GUIStyle locStyle;
     int wait;
     float radarRadius;
     string radarType, APIkey, radarSensor;
     string googleRespStr;
     
     void Start ()
     {
         Screen.sleepTimeout = SleepTimeout.NeverSleep;
         radarRadius = 1000f;
         radarType = "restaurant";
         APIkey = "MyAPIkey";
         radarSensor = "false";
     }
     
     void RetrieveGPSData()
     {
         currentGPSPosition = Input.location.lastData;
         gpsString = "Lat: " + currentGPSPosition.latitude + "  Lon: " + currentGPSPosition.longitude + "  Alt: " + currentGPSPosition.altitude + 
             "  HorAcc: " + Input.location.lastData.horizontalAccuracy + "  VerAcc: " + Input.location.lastData.verticalAccuracy + "  TS: " + Input.location.lastData.timestamp;
     }
     
     void OnGUI ()
     {
         GUI.Box (ScaleRect.scaledRect(25,25,700,100), "");
         GUI.Label (ScaleRect.scaledRect(35,25,700,100), gpsString, locStyle);
         
         GUI.Box (ScaleRect.scaledRect(25,130,700,800), "");
         GUI.Label (ScaleRect.scaledRect(35,135,700,800), "" +googleRespStr, locStyle);
         
 #if PC
         Debug.Log("On PC / Don't have GPS");
 #elif !PC
         Input.location.Start(10f,1f);
         int wait = 1000;
 
         if(Input.location.isEnabledByUser)
         {
             while(Input.location.status == LocationServiceStatus.Initializing && wait>0)
             {
                 wait--;
             }
             if (Input.location.status == LocationServiceStatus.Failed)
             {}
 
             else
             {
                 RetrieveGPSData();
                 StartCoroutine(Radar());
             }
         }
         else
         {
             GameObject.Find("gps_debug_text").guiText.text = "GPS not available";
         }
 #endif        
     }
 
     IEnumerator Radar ()
     {
         string radarURL = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=" + currentGPSPosition.latitude + "," + currentGPSPosition.longitude + "&radius=" + radarRadius + "&types=" + radarType + "&sensor=false" + radarSensor + "&key=" + APIkey;
         WWW googleResp = new WWW(radarURL);
         yield return googleResp;
         googleRespStr = googleResp.text;
         print (googleRespStr);        
     }
 }

I am getting correct latitude and longitude coordinates but for place, all I get is this,

 {
    "debug_info" : [],
    "html_attributions" : [],
    "results" : [],
    "status" : "REQUEST_DENIED"
 }

Has anyone used places api in their unity project? It would be great if someone could give me some hint.

Thanks in advance!

Merry Christmas & Happy New Year!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by jainam · Jan 09, 2014 at 05:03 AM

got it working. turns out, if you leave the SHA-1 fingerprint field empty, then also google create API key which can be used in the app.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lamp · Feb 03, 2014 at 09:26 PM 0
Share

Hi was looking what you have done trying to recreate it myself. I was getting the same error you were but $$anonymous$$us the first line "debug_info". I tried it firs with a SHA fingerprint in the google api console place using mykey and then again with a new key without a fingerprint both to no success. Have you any other info regards to pitfalls or something else i may have over looked?

avatar image jainam · Feb 04, 2014 at 04:10 AM 0
Share

that's strange.... just want to make sure, by "without a fingerprint" you mean, you left the entire field empty, right? not even the package name (com.company.product)? while creating the API key, which option did you select from Server key, Browser key, Android key and iOS key? I had created a key for Android and it worked well. After reading your comment, I created a new key for iOS and browser also and they both worked well. Could you mention all the steps you followed?

avatar image lamp · Feb 04, 2014 at 09:35 AM 0
Share

Ok so previously not even the test links were working in the browser but they seem to be working now. Still no luck on device though. Is there anything aditional in terms of code or in your project beyond what you have shown and the SimpleJson script?

Went through the google console ticking on the apis i wanted to use, in this case i only wanted the places api. Generated a new key for android, leaving the field blank. And then was working between your code and the steps you had linked.

I left the entire field blank yes and had created a Android key which now works int he browser but cant get it working on device. I was just following the link you had included and parts of the code you had posted but with some alterations to display and when it was called etc

avatar image jainam · Feb 05, 2014 at 04:54 AM 0
Share

nope.....there is nothing additional in my code. this is really strange that you Android key is working on the browser but not on the device. if you could send your project, I could have a look and tell you.

avatar image lamp · Feb 05, 2014 at 08:47 AM 0
Share

I was giving it one last look over this morning before packing it up to send to you and i discovered what the problem was. In the URL that i had took from your code above it was had '"radarSensor=false"+radar sensor'. So the url on the device was reading as sensor=falsefalse. removed that and its now working on device.

Excellent i can now start playing with the results i can get. Thanks loads for the help. Is really appreciated. Am relatively new to the unity forums so i would up-vote if i knew how

Thanks again

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Google map apis in unity (Directions,marker,...) 0 Answers

How do you constrain googleMaps to a window? 0 Answers

Reading JSON response from Google Sheets in unity ( most places have WWW.text) 1 Answer

(Sorry for my english) why when i use embed google api works well in unity editor, but it doesn't in android ? (only shows me a interrogation sign) 0 Answers

Get google account on webgl 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges