Topic: DistanceAndDirectionExample not working for me...

Super-newbie question I guess:

I try to figure out how to get distance between two markers (or between user and custom marker).
I searched and came across many answers to simple check out DistanceAndDirectionExample.cs
I attach this script to the map gameobject, and nothing happens, nothing in console.

Probably doing something dumb, but appreciate feedback on this.


Re: DistanceAndDirectionExample not working for me...


Very strange.
If you had not entered the key, you would have had a warning in the console.
If you had not enabled Directions API in Google Developer Console, then you would have received an error message from Google.

Are the rest of Google APIs working correctly for you?

Re: DistanceAndDirectionExample not working for me...

Ah ok so this example only works when using Google?.. I'm using CartoDB, so I guess that might the the problem? I purchased and activated onlinemaps correctly, so that can't be the issue.

I'm  trying to do something (seemingly) simple: read out the user's position, and calculate the distance (in meters) between user and the markers that are generated with the UIBubblePopup example (and have that distance displayed in the BubblePopup (which I guess I have to add some variables to;)).

Anyway I found heaps of similar questions, but still haven't got it to work. (Just to explain my level of dumbness: I'm a (3D) designer, and been messing around with unity for quite some time on and off, but I'm not a great coder, even after all these years (bit of actionscript, bit of processing, bit of C#..)


Re: DistanceAndDirectionExample not working for me...

You can use tiles, elevations, and services in any combination, such as tiles from CartoDB, ArcGIS elevations, and Google Directions API + Open Street Map Overpass API.

Sorry, I mixed up the examples.
You are writing about DistanceAndDirectionExample, and I confused this with DistanceAndDurationExample.
DistanceAndDirectionExample does not require any services.

In this example, to display the values in the console, you need to click Calc button in the upper left corner of Game View.
If after clicking the button you do not see the values in the console, it means that you have simply disabled the display of messages in the console (bubble with an exclamation mark in the upper right part of Console window).

Re: DistanceAndDirectionExample not working for me...

Ah thanks, so yeah pretty dumb I didn't notice the button being generated.
To test out I tried to manually fill in the x and y for both user location as for the marker inputfields. Still a bit confused here (bear with me haha), when filling in lat and lon on both the distance was about correct, so is my assumption correct that one needs to get the lat/lon values in there and not the x and y coordinates on screen?

Little typo by the way: shouldn't "userCoordinares" be "userCoordinates"? wink
(just trying to look less dumb ;b)

Re: DistanceAndDirectionExample not working for me...

1. Unfortunately, I didn't understand this question. Please rephrase this.
2. Yes, it's just a typo. Thanks for showing me this.

Re: DistanceAndDirectionExample not working for me...

Thanks, I try to rephrase:

In DistanceAndDirectionExample.cs there are the following variables:
User Coordinates x and y
Marker Coordinates x and y
Compass true heading.

I filled in "true" lattitude an longitude values in here to calculate the distance: so in this case

2.1815 in user coordinates x
41.390391 in user coordinates y
2.180965 in marker coordinates x
41.387665 in marker coordinates y

i played the scene, pressed calculate and the distance was around 360 meters, which is about right. So I was wondering if my assumption is correct that I should use lat en lon values in the x and y fields, and not screen coordinates?

Re: DistanceAndDirectionExample not working for me...

Yes, in this example XY is the coordinates. X is longitude, Y is latitude.