/* INFINITY CODE 2013-2016 */ /* http://www.infinity-code.com */ using System.Collections.Generic; using UnityEngine; namespace InfinityCode.OnlineMapsExamples { [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/FindPlacesExample")] public class FindPlaces : MonoBehaviour { public GameObject markerPrefab; private OnlineMapsMarker3D marker3D; public int defaultZoom = 17; bool gpsInit = false; private void Start() { // Get instance of LocationService. OnlineMapsLocationService locationService = OnlineMapsLocationService.instance; if (locationService == null) { Debug.LogError( "Location Service not found.\nAdd Location Service Component (Component / Infinity Code / Online Maps / Plugins / Location Service)."); return; } // Subscribe to the change location event. locationService.OnLocationChanged += OnLocationChanged; } private void update() { OnlineMapsLocationService locationService = OnlineMapsLocationService.instance; // Subscribe to the change location event. //locationService.OnLocationChanged += OnLocationChanged; } private void OnComplete(string s) { OnlineMapsFindPlacesResult[] results = OnlineMapsFindPlaces.GetResults(s); if (results == null) { Debug.Log("Error"); Debug.Log(s); return; } List multipleStaticMarkers = new List(); List multiplemarkers = new List(); OnlineMapsControlBase3D control = GetComponent(); foreach (OnlineMapsFindPlacesResult result in results) { Debug.Log(result.name); Debug.Log(result.location); OnlineMapsMarker marker = OnlineMaps.instance.AddMarker(result.location, result.name); marker3D = control.AddMarker3D(result.location, markerPrefab); multipleStaticMarkers.Add(marker); marker3D.range = new OnlineMapsRange(1, 20); multiplemarkers.Add (marker3D); marker3D.OnClick += OnMarkerClick; OnlineMaps.instance.OnChangeZoom += OnChangeZoom; } Vector2 center; int zoom; OnlineMapsUtils.GetCenterPointAndZoom(multipleStaticMarkers.ToArray(), out center, out zoom); OnlineMaps.instance.position = center; OnlineMaps.instance.zoom = zoom + 1; //Added Codes OnlineMaps api = OnlineMaps.instance; // Add OnClick events to static markers // foreach (OnlineMapsMarker marker in api.markers) //added codes // { // marker.OnClick += OnMarkerClick; // } // Add OnClick events to 3d markers foreach (OnlineMapsMarker marker3D in api.markers) //added codes { marker3D.OnClick += OnMarkerClick; } // Subscribe to change zoom. OnlineMaps.instance.OnChangeZoom += OnChangeZoom; } private void OnMarkerClick(OnlineMapsMarkerBase marker3D) //added codes { // Show in console marker label. //Debug.Log(marker3D.label); Application.LoadLevel("KudanAR"); } // When the location has changed private void OnLocationChanged(Vector2 position) { if (gpsInit == false){ gpsInit = true; OnlineMapsFindPlaces.FindNearby( position,//<----added code 1000, "API", // <----------------------------- Google API Key "jollibee", null, "restaurant").OnComplete += OnComplete; } } private void OnChangeZoom() { float originalScale = 5 << defaultZoom; float currentScale = 5 << OnlineMaps.instance.zoom; marker3D.scale = currentScale / originalScale; } } }