Skip to content

Instantly share code, notes, and snippets.

@kazumalab
Last active October 25, 2016 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazumalab/008ac4a8fbccc77f1c2890f3457102c8 to your computer and use it in GitHub Desktop.
Save kazumalab/008ac4a8fbccc77f1c2890f3457102c8 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Xml;
using System;
public class Gmap : MonoBehaviour {
public string PlaceName;
private double latitude;
public double Latitude {
set { this.latitude = value; }
get { return this.latitude; }
}
private double longitude;
public double Longitude {
set { this.longitude = value; }
get { return this.longitude; }
}
private Texture gmaptexture;
public Texture GmapTexture {
set { this.gmaptexture = value; }
get { return this.gmaptexture; }
}
private string GeoURL = "http://www.geocoding.jp/api/?q=";
public Gmap (string pname) {
this.PlaceName = pname;
this.Latitude = 0d;
this.Longitude = 0d;
}
public IEnumerator GetGeoCode () {
print (this.GeoURL);
WWW www = new WWW (this.GeoURL + this.PlaceName);
print (this.GeoURL + this.PlaceName);
yield return www;
if (www.error == null) {
XmlDocument xmlDoc = new XmlDocument ();
xmlDoc.LoadXml (www.text);
XmlNodeList nodes = xmlDoc.GetElementsByTagName ("result");
foreach (XmlNode node in nodes) {
XmlNode childNode = node.FirstChild;
int count = 0;
do {
if (++count > 10)
break;
if (childNode.Name == "coordinate") {
XmlNodeList list = childNode.ChildNodes;
int c = 0;
foreach (XmlNode n in list) {
if (c == 0) {
this.Latitude = Convert.ToDouble (n.FirstChild.Value);
} else if (c == 1) {
this.Longitude = Convert.ToDouble (n.FirstChild.Value);
}
c++;
}
}
} while((childNode = childNode.NextSibling) != null);
}
} else {
Debug.LogError (www.error);
}
}
public IEnumerator GetGmapsImage (float zoom) {
string url = "http://maps.googleapis.com/maps/api/staticmap?center=" + this.Latitude + "," + this.Longitude + "&zoom=" + zoom + "&size=" + 300 + "x" + 200 + "&markers=size:mid%7Color:red%7C" + this.Latitude+ "," + this.Longitude;
WWW www = new WWW (url);
yield return www;
if (www.error == null) {
this.GmapTexture = www.texture;
} else {
Debug.LogError (www.error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment