├── .gitignore ├── CHANGELOG.md ├── CHANGELOG.md.meta ├── LICENSE ├── LICENSE.meta ├── README.md ├── README.md.meta ├── Resources.meta ├── Resources ├── countries.json ├── countries.json.meta ├── usastates-highres.json ├── usastates-highres.json.meta ├── usastates-lowres.json ├── usastates-lowres.json.meta ├── usastates-medres.json └── usastates-medres.json.meta ├── Runtime.meta ├── Runtime ├── CountryReverseGeocodeService.cs ├── CountryReverseGeocodeService.cs.meta ├── Data.meta ├── Data │ ├── DefaultCountryDataProvider.cs │ ├── DefaultCountryDataProvider.cs.meta │ ├── DefaultUSAStateDataProvider.cs │ ├── DefaultUSAStateDataProvider.cs.meta │ ├── IReverseGeocodeDataProvider.cs │ ├── IReverseGeocodeDataProvider.cs.meta │ ├── JsonReverseGeocodeDataProvider.cs │ └── JsonReverseGeocodeDataProvider.cs.meta ├── Models.meta ├── Models │ ├── AreaData.cs │ ├── AreaData.cs.meta │ ├── Geolocation.cs │ ├── Geolocation.cs.meta │ ├── LocationInfo.cs │ └── LocationInfo.cs.meta ├── ReverseGeocoder.cs ├── ReverseGeocoder.cs.meta ├── UnityReverseGeocoder.asmdef └── UnityReverseGeocoder.asmdef.meta ├── package.json └── package.json.meta /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | These are the release notes for the UnityReverseGeocoder package. 3 | 4 | # 2020/06/26 5 | Initial release. 6 | -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 222d297c95b4f7e4d967d4a04496b790 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Hossein Shah 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32120ac864581654a9ed031f5ca7a34d 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReverseGeocoderForUnity 2 | [![openupm](https://img.shields.io/npm/v/com.nosuchstudio.reversegeocoder?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.nosuchstudio.reversegeocoder/) 3 | 4 | Reverse Geocoder for Unity allows you to look up world coordinates (latitude, longitude) and get the country / US state the query point falls into. The code is offline and performs no network calls. 5 | 6 | The code is based off [Wibci.CountryReverseGeocode](https://github.com/InquisitorJax/Wibci.CountryReverseGeocode). 7 | 8 | The library can be used with custom data. For example you could gather data for provinces of countries other than the US and use it with this library. The sample .json files for US and world countries are included in this package. 9 | 10 | ### Why not use [Wibci.CountryReverseGeocode](https://github.com/InquisitorJax/Wibci.CountryReverseGeocode) directly? 11 | - Less code: That project is a general C# project, with all the NUnit tests and a gen project. Not suitable for inclusion in a Unity project. This project is way smaller and contians the minimal set of files from the original package. It reduces the binary build file of your game. 12 | 13 | - Basic Unity integration: This package adds a thin MonoBehavoiur wrapper around the main service class for use with Unity. The showcase project (this) includes a sample Unity scene that performs reverse Geocode queries. 14 | 15 | - This package also gets around [a build problem](https://issuetracker.unity3d.com/issues/il2cpp-build-hangs-while-building-a-project-with-a-large-array-of-strings) in Unity by removing the large class data initializers and loading the data at runtime from .json files. 16 | 17 | ## Installation 18 | 19 | :warning: This package has a dependency on [Newtonsoft.json for Unity](https://github.com/jilleJr/Newtonsoft.Json-for-Unity). Install that first. 20 | 21 | ### Install via [Git URLs](https://docs.unity3d.com/Manual/upm-git.html) 22 | 23 | Add this git URL in Unity's package manager. 24 | ``` 25 | https://github.com/hk1ll3r/ReverseGeocoderForUnity 26 | ``` 27 | 28 | ### Install via Traditional .unitypackage File 29 | Releases contain the `ReverseGeocoderForUnity.unitypackage`. 30 | 31 | ### Install via [OpenUPM](https://openupm.com/) 32 | ``` 33 | openupm add com.nosuchstudio.reversegeocoder 34 | ``` 35 | 36 | ### Install via Unity Asset Store 37 | This package is available on Unity Asset Store: (http://u3d.as/1WT5). 38 | 39 | ## License 40 | This package is licensed under The MIT License (MIT) 41 | 42 | Copyright © 2020 Hoss Shah (hk1ll3r) 43 | https://github.com/hk1ll3r/ReverseGeocoderForUnity 44 | 45 | See full copyrights in LICENSE.md inside repository 46 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0780803fd4b0b7d428cf8f95264cc5c9 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c6e677e0f82e6049a4bad2c56a57d4a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Resources/countries.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1cd38168e154bbf43850efe23e4a5e54 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Resources/usastates-highres.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3fd6cbcb5bb8b64e92ac13a0cc01e3c 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Resources/usastates-lowres.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 333050a1aaef54444b41a98146cfc011 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Resources/usastates-medres.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 600d73f7810f73f47b5cc1e2ad1ac6ac 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7630ec469a892e64588d4e474d18af55 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/CountryReverseGeocodeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Wibci.CountryReverseGeocode.Data; 5 | using Wibci.CountryReverseGeocode.Models; 6 | 7 | namespace Wibci.CountryReverseGeocode 8 | { 9 | public interface ICountryReverseGeocodeService 10 | { 11 | LocationInfo FindCountry(GeoLocation location); 12 | 13 | LocationInfo FindUSAState(GeoLocation location); 14 | 15 | LocationInfo FindAreaData(GeoLocation location, List areaDataList); 16 | } 17 | 18 | public class CountryReverseGeocodeService : ICountryReverseGeocodeService 19 | { 20 | public CountryReverseGeocodeService() 21 | { 22 | CountryDataProvider = new DefaultCountryDataProvider(); 23 | USAStateDataProvider = new DefaultUSAStateDataProvider(); 24 | } 25 | public CountryReverseGeocodeService(IReverseGeocodeDataProvider countryDataProvider, IReverseGeocodeDataProvider statesDataProvider) 26 | { 27 | CountryDataProvider = countryDataProvider; 28 | USAStateDataProvider = statesDataProvider; 29 | } 30 | public IReverseGeocodeDataProvider CountryDataProvider { get; set; } 31 | public IReverseGeocodeDataProvider USAStateDataProvider { get; set; } 32 | 33 | public LocationInfo FindCountry(GeoLocation location) 34 | { 35 | if (CountryDataProvider == null) throw new Exception("No country data provider set. Set via 'CountryDataProvider' property."); 36 | return FindAreaData(location, CountryDataProvider.Data); 37 | } 38 | 39 | public LocationInfo FindUSAState(GeoLocation location) 40 | { 41 | if (CountryDataProvider == null) throw new Exception("No usa state data provider set. Set via 'USAStateDataProvider' property."); 42 | return FindAreaData(location, USAStateDataProvider.Data); 43 | } 44 | 45 | public LocationInfo FindAreaData(GeoLocation location, List areaDataList) 46 | { 47 | var matchedAreaData = areaDataList.Find(areaData => IsLocationInArea(location, areaData)); 48 | return matchedAreaData != null ? LocationInfo.FromAreaData(matchedAreaData) : null; 49 | } 50 | 51 | private bool IsLocationInArea(GeoLocation location, AreaData data) 52 | { 53 | return data.coordinates.Any(polygon => 54 | { 55 | List locations = polygon.Select(point => new GeoLocation { Latitude = point[1], Longitude = point[0] }).ToList(); 56 | return location.IsInPolygon(locations); 57 | }); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Runtime/CountryReverseGeocodeService.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21df6ccf2a311be41b417385771ca3cf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Data.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 443359dc527c7984f86d36a7f678ebc6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Data/DefaultCountryDataProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Wibci.CountryReverseGeocode.Models; 3 | 4 | namespace Wibci.CountryReverseGeocode.Data 5 | { 6 | public class DefaultCountryDataProvider : IReverseGeocodeDataProvider 7 | { 8 | List _data = new List(); 9 | 10 | public List Data 11 | { 12 | get 13 | { 14 | return _data; 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/Data/DefaultCountryDataProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35a2da8b57eaabf44a353ba1fb858b46 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Data/DefaultUSAStateDataProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Wibci.CountryReverseGeocode.Models; 3 | 4 | namespace Wibci.CountryReverseGeocode.Data 5 | { 6 | public class DefaultUSAStateDataProvider : IReverseGeocodeDataProvider 7 | { 8 | List _data = new List(); 9 | 10 | public List Data 11 | { 12 | get 13 | { 14 | return _data; 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Runtime/Data/DefaultUSAStateDataProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45605f1d56dcd8f4aa6982e6d28c08dd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Data/IReverseGeocodeDataProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Wibci.CountryReverseGeocode.Models; 5 | 6 | namespace Wibci.CountryReverseGeocode.Data 7 | { 8 | public interface IReverseGeocodeDataProvider 9 | { 10 | List Data { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Runtime/Data/IReverseGeocodeDataProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02df543913abe9c46bce39ca45d8544c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Data/JsonReverseGeocodeDataProvider.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using Wibci.CountryReverseGeocode.Models; 4 | 5 | namespace Wibci.CountryReverseGeocode.Data 6 | { 7 | public class JsonDataProvider : IReverseGeocodeDataProvider 8 | { 9 | List _data = new List(); 10 | 11 | public JsonDataProvider(string json) 12 | { 13 | _data = JsonConvert.DeserializeObject>(json); 14 | } 15 | 16 | public List Data 17 | { 18 | get 19 | { 20 | return _data; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Runtime/Data/JsonReverseGeocodeDataProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d4b8c71becb731c44bf1e7e3ccf68252 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Models.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8eb1ab751bd38644786e415b0911c144 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Models/AreaData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Wibci.CountryReverseGeocode.Models 4 | { 5 | //classes used to deserialize json data in Data folder: 6 | 7 | public class AreaData { 8 | public AreaData(string id, string name, List>> coordinates) 9 | { 10 | this.id = id; 11 | this.name = name; 12 | this.coordinates = coordinates; 13 | } 14 | 15 | public string id { get; set; } 16 | public string name { get; set; } 17 | 18 | public List>> coordinates { get; set; } 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /Runtime/Models/AreaData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c59b970ebcfc59341ac28859d6b157a6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Models/Geolocation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | 5 | namespace Wibci.CountryReverseGeocode.Models 6 | { 7 | public class GeoLocation 8 | { 9 | public string Description { get; set; } 10 | 11 | public double Latitude { get; set; } 12 | 13 | public double Longitude { get; set; } 14 | 15 | public static bool AreEqual(GeoLocation location1, GeoLocation location2) 16 | { 17 | if (ReferenceEquals(location1, null) ^ ReferenceEquals(location2, null)) 18 | return false; 19 | 20 | return ReferenceEquals(location1, location2) || (location1.Latitude == location2.Latitude && location1.Longitude == location2.Longitude); 21 | } 22 | 23 | public static GeoLocation FromWellKnownText(string text) 24 | { 25 | if (string.IsNullOrEmpty(text)) 26 | { 27 | return null; 28 | } 29 | else 30 | { 31 | GeoLocation location = new GeoLocation(); 32 | 33 | int firstParenth = text.IndexOf("(") + 1; 34 | int secondParent = text.IndexOf(")"); 35 | string locationString = text.Substring(firstParenth, secondParent - firstParenth).Trim(); 36 | string[] locations = locationString.Split(' '); 37 | double latitude = double.Parse(locations[1]); 38 | double longitude = double.Parse(locations[0]); 39 | 40 | location.Latitude = latitude; 41 | location.Longitude = longitude; 42 | 43 | return location; 44 | } 45 | } 46 | 47 | public static bool IsInCloseProximity(GeoLocation location1, GeoLocation location2, int rounding = 4) 48 | { 49 | if (ReferenceEquals(location1, null) ^ ReferenceEquals(location2, null)) 50 | return false; 51 | 52 | return ReferenceEquals(location1, location2) || (Math.Round(location1.Latitude, rounding) == Math.Round(location2.Latitude, rounding) 53 | && Math.Round(location1.Longitude, rounding) == Math.Round(location2.Longitude, rounding)); 54 | } 55 | 56 | public bool IsInPolygon(IList polygonLocations) 57 | { 58 | //based in PIP: https://en.wikipedia.org/wiki/Point_in_polygon 59 | int i, j; 60 | bool c = false; 61 | for (i = 0, j = polygonLocations.Count - 1; i < polygonLocations.Count; j = i++) 62 | { 63 | if ((((polygonLocations[i].Latitude <= Latitude) && (Latitude < polygonLocations[j].Latitude)) 64 | || ((polygonLocations[j].Latitude <= Latitude) && (Latitude < polygonLocations[i].Latitude))) 65 | && (Longitude < (polygonLocations[j].Longitude - polygonLocations[i].Longitude) * (Latitude - polygonLocations[i].Latitude) 66 | / (polygonLocations[j].Latitude - polygonLocations[i].Latitude) + polygonLocations[i].Longitude)) 67 | 68 | c = !c; 69 | } 70 | 71 | return c; 72 | } 73 | 74 | public override string ToString() 75 | { 76 | return SerializeToString(); 77 | } 78 | 79 | public string ToWellKnownText() 80 | { 81 | return string.Format(CultureInfo.InvariantCulture, "POINT ({0})", SerializeToString()); 82 | } 83 | 84 | private string SerializeToString() 85 | { 86 | const string template = "{0} {1} {2} {3}"; 87 | string longitude = Longitude.ToString(CultureInfo.InvariantCulture); 88 | string latitude = Latitude.ToString(CultureInfo.InvariantCulture); 89 | string altitude = string.Empty; 90 | string measure = string.Empty; 91 | //if (Altitude.HasValue) 92 | //{ 93 | // altitude = " " + Altitude.Value.ToString(CultureInfo.InvariantCulture); 94 | // if (Measure.HasValue) 95 | // { 96 | // measure = " " + Measure.Value.ToString(CultureInfo.InvariantCulture); 97 | // } 98 | //} 99 | 100 | return string.Format(CultureInfo.InvariantCulture, template, longitude, latitude, altitude, measure); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /Runtime/Models/Geolocation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 07a14df605d57af4393c4bca8c6a245f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Models/LocationInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Wibci.CountryReverseGeocode.Models 2 | { 3 | public class LocationInfo 4 | { 5 | public static LocationInfo FromAreaData(AreaData ad) { 6 | return new LocationInfo(ad.id, ad.name); 7 | } 8 | public LocationInfo(string id, string name) 9 | { 10 | Id = id; 11 | Name = name; 12 | } 13 | public string Id { get; private set; } 14 | public string Name { get; private set; } 15 | } 16 | } -------------------------------------------------------------------------------- /Runtime/Models/LocationInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0bc9d5296d1a9414e9b3933025ae7593 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/ReverseGeocoder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Wibci.CountryReverseGeocode; 5 | using Wibci.CountryReverseGeocode.Data; 6 | using Wibci.CountryReverseGeocode.Models; 7 | 8 | public class ReverseGeocoder : MonoBehaviour 9 | { 10 | [SerializeField] TextAsset _statesJson; 11 | [SerializeField] TextAsset _countriesJson; 12 | 13 | private CountryReverseGeocodeService _geocoderService; 14 | 15 | private void Awake() 16 | { 17 | var statesDataProvider = new JsonDataProvider(_statesJson.text); 18 | var countriesDataProvider = new JsonDataProvider(_countriesJson.text); 19 | _geocoderService = new CountryReverseGeocodeService(countriesDataProvider, statesDataProvider); 20 | } 21 | 22 | public string ReverseGeocodeCountry(float lon, float lat) 23 | { 24 | if (_geocoderService == null) return null; 25 | return _geocoderService.FindCountry(new GeoLocation() { Longitude = lon, Latitude = lat })?.Name; 26 | } 27 | 28 | public string ReverseGeocodeUSAState(float lon, float lat) 29 | { 30 | if (_geocoderService == null) return null; 31 | return _geocoderService.FindUSAState(new GeoLocation() { Longitude = lon, Latitude = lat })?.Name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Runtime/ReverseGeocoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a8dc10e0387815429766d68872a5051 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/UnityReverseGeocoder.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "UnityReverseGeocoder" 3 | } 4 | -------------------------------------------------------------------------------- /Runtime/UnityReverseGeocoder.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 979ff911d02ede543b1aade472a52b11 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.nosuchstudio.reversegeocoder", 3 | "displayName": "Reverse Geocoder for Unity", 4 | "version": "1.0.0", 5 | "unity": "2019.3", 6 | "description": "Reverse Geocoder for Unity let's you look up location coordinates (latitude, longitude) to get the country and USA state the query point is in. All code is offline and extensible.", 7 | "keywords": [ 8 | "geocode", 9 | "geocoder", 10 | "reverse", 11 | "location" 12 | ], 13 | "author": { 14 | "name": "hk1ll3r", 15 | "email": "hossein.shbz@gmail.com", 16 | "url": "https://www.hossein-shahbazi.com" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/hk1ll3r/ReverseGeocoderForUnity" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19ffdc05a41fb7a45be7934d25994afa 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------