- Home /
Creating an UI GPS map
Hello everyone.
First i'm not English so my post will probably have some mistakes.
I'm working on a offline GPS map system working in a UI canvas, i took some screenshots of maps and get the coordinates at the up left and down right corners of each map. My script actually takes all thoses variables and then do some maths to place a marker in the map corresponding to the position of the player. The problem is that it is misplaced to the correct position in the y axis. Here's my script, he got two different lines of code for setting the position of the marker depending of if i'm testing on pc or android.
I think you should only watch at the beginning of the update function where i change the position of my marker cause the other functionality works and i think it's only a math problem.
Thank you for watching.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Android;
using System.IO;
public class gps_locationpoint : MonoBehaviour
{
private float Lat;
private float Lon;
private float factor_x;
private float factor_y;
public Vector2 ul_Corner; //up left corner
public Canvas canvas;
public Vector2 dr_Corner; //down right corner
public Vector2 fakepos; //the position while testing on pc
public bool isUpdating;
private Image image;
float marge;
Transform trans;
private RectTransform self;
public RectTransform map;
public RectTransform offset_obj;
Vector3 TouchStart;
// Start is called before the first frame update
void Start()
{
self = gameObject.transform.GetComponent<RectTransform>();
image = gameObject.transform.parent.GetComponent<Image>();
trans= GetComponent<RectTransform>();
TouchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
// Update is called once per frame
private void Update()
{//this is the calculation for pc testing
trans.position = new Vector3(((map.rect.width*(fakepos.x-ul_Corner.x)/(dr_Corner.x-ul_Corner.x)))*(canvas.scaleFactor)+map.position.x+self.rect.width/2,(((map.rect.height/2*(fakepos.y-ul_Corner.y)/(dr_Corner.y-ul_Corner.y)))*(canvas.scaleFactor))+map.position.y-self.rect.width/2,0);
There's still code after that but those pieces of code are not involved in my problem Thanks for watching
Your answer
Follow this Question
Related Questions
How do I get this code to run specified amount of times 1 Answer
MapBox - Javascript API work in unity? 1 Answer
GPS Locate.permission Android? 0 Answers
Lat Long to Unity world coordinates 1 Answer
Change orbit while rotating. 2 Answers