Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mfarrell806 · Dec 19, 2016 at 05:10 PM · uiinputuser interfacesciptgoogle-earth

Link UI Input field to Google Map Script

OK, so I have an area in my 'game' that is actually a Google Earth map. This is where the game pieces are placed.

What I would like is to have is a way for the user to enter or acquire his desire GPS coordinates and enter them during the game.

It looks like this could be done using UI Input Field(Script). Typical that this is beyond my current knowledge. It would be great if I could get Input Field(s) to offer the player a place to enter the values for Lat Long Scale

Here is the Google Map script:

 using UnityEngine;
 using System.Collections;
 
 public class GoogleMap : MonoBehaviour
 {
     public enum MapType
     {
         RoadMap,
         Satellite,
         Terrain,
         Hybrid
     }
     public bool loadOnStart = true;
     public bool autoLocateCenter = true;
     public GoogleMapLocation centerLocation;
     public int zoom = 13;
     public MapType mapType;
     public int size = 512;
     public bool doubleResolution = false;
     public GoogleMapMarker[] markers;
     public GoogleMapPath[] paths;
 
     void Start()
     {
         if (loadOnStart) Refresh();
     }
 
     public void Refresh()
     {
         if (autoLocateCenter && (markers.Length == 0 && paths.Length == 0))
         {
             Debug.LogError("Auto Center will only work if paths or markers are used.");
         }
         StartCoroutine(_Refresh());
     }
 
     IEnumerator _Refresh()
     {
         var url = "http://maps.googleapis.com/maps/api/staticmap";
         var qs = "";
         if (!autoLocateCenter)
         {
             if (centerLocation.address != "")
                 qs += "center=" + WWW.UnEscapeURL(centerLocation.address);
             else
             {
                 qs += "center=" + WWW.UnEscapeURL(string.Format("{0},{1}", centerLocation.latitude, centerLocation.longitude));
             }
 
             qs += "&zoom=" + zoom.ToString();
         }
         qs += "&size=" + WWW.UnEscapeURL(string.Format("{0}x{0}", size));
         qs += "&scale=" + (doubleResolution ? "2" : "1");
         qs += "&maptype=" + mapType.ToString().ToLower();
         var usingSensor = false;
 #if UNITY_IPHONE
         usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;
 #endif
         qs += "&sensor=" + (usingSensor ? "true" : "false");
 
         foreach (var i in markers)
         {
             qs += "&markers=" + string.Format("size:{0}|color:{1}|label:{2}", i.size.ToString().ToLower(), i.color, i.label);
             foreach (var loc in i.locations)
             {
                 if (loc.address != "")
                     qs += "|" + WWW.UnEscapeURL(loc.address);
                 else
                     qs += "|" + WWW.UnEscapeURL(string.Format("{0},{1}", loc.latitude, loc.longitude));
             }
         }
 
         foreach (var i in paths)
         {
             qs += "&path=" + string.Format("weight:{0}|color:{1}", i.weight, i.color);
             if (i.fill) qs += "|fillcolor:" + i.fillColor;
             foreach (var loc in i.locations)
             {
                 if (loc.address != "")
                     qs += "|" + WWW.UnEscapeURL(loc.address);
                 else
                     qs += "|" + WWW.UnEscapeURL(string.Format("{0},{1}", loc.latitude, loc.longitude));
             }
         }
 
 
         var req = new WWW(url + "?" + qs);
         yield return req;
         GetComponent<Renderer>().material.mainTexture = req.texture;
     }
 
 
 }
 
 public enum GoogleMapColor
 {
     black,
     brown,
     green,
     purple,
     yellow,
     blue,
     gray,
     orange,
     red,
     white
 }
 
 [System.Serializable]
 public class GoogleMapLocation
 {
     public string address;
     public float latitude;
     public float longitude;
 }
 
 [System.Serializable]
 public class GoogleMapMarker
 {
     public enum GoogleMapMarkerSize
     {
         Tiny,
         Small,
         Mid
     }
     public GoogleMapMarkerSize size;
     public GoogleMapColor color;
     public string label;
     public GoogleMapLocation[] locations;
 
 }
 
 [System.Serializable]
 public class GoogleMapPath
 {
     public int weight = 5;
     public GoogleMapColor color;
     public bool fill = false;
     public GoogleMapColor fillColor;
     public GoogleMapLocation[] locations;
 }


The attached image shows the Google Map script input fields I would want to link to the UI Input Fields and then a way to update the game play area to display proper Map, and scale when entered by the user.

Thanks!

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
0

Answer by mfarrell806 · Jan 03, 2017 at 05:57 PM

Looks like I forgot to attach the image:alt text

I would like to allow the user to input their location data with a UI button or an input field somehow, and have the game object displaying the map image update/refresh on entry.

Currently the location information is input before game runtime.


googlemap.jpg (38.9 kB)
Comment
Add comment · 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

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

114 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 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 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 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 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 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

Method Skipping Inputs 2 Answers

I have an issue with the code for Submenu. Someone to help me ? 1 Answer

Detect if mouse has clicked on a UI element? 0 Answers

NumericUpDown input field 1 Answer

Creating a Pointer to control UI elements (with and without VR) 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