cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Reset marker on Googlemap if selected location is 0000 : 0000

gpaillot
1-Newbie

Reset marker on Googlemap if selected location is 0000 : 0000

Hi,

I have a mashup where I need to locate on map the position of connected devices.

Now i've got 2 devices.

The first have a real location : it is diplayed on my googlemap with a marker.

The 2nd have no location, the value is 0.0000 : 0.0000.


When I select the 2nd device, the marker on the map does not reset -> i still view the location of 1st device 

I've got other properties which are updated fine by mey GetProperties call. 

How can I make reset my googlemap if there is no real location ? I don't find any option to do this on the widget.

I have found this function below on the google developper's website. But how can I implement it on my Mashup ?

// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
  clearMarkers
();
  markers
= [];

}


Thanks for your help



21 REPLIES 21
Aanjan
9-Granite
(To:gpaillot)

Gaelle, I believe 0.0000 : 0.0000 points to no location at all; which is why you don't see the marker move anywhere. If you want to hide the markers if there is no location, you could possibly write a service with output set to either true or false and bind that to the 'ShowMarkers' property. If the service outputs false in case of no location, the marker would simply disappear. Does this make sense?

Hi Annjan, it's a good idea, thank you ! I will do this tomorrow morning and come back to tell the result !

Thanks again

Aanjan
9-Granite
(To:gpaillot)

No problem, let me know how it works out

Hi, now I've got an issue with the service

I'm not a js expert so ...

My service has no input and a boolean for output as you suggested.

!

var showmarker = true;

var mylocation = String(me.gpsLocation);

if( mylocation = "0.0000 : 0.0000")

{

    showmarker = false ;

I've got this error when i use the test button to execute it :

"Unable To Convert From org.mozilla.javascript.UniqueTag to BOOLEAN"

Do you know what's wrong with my service ?

You could use the localeCompare method to compare strings, e.g.

//string comparison test

//localeCompare returns -1 if strings are not equal, 0 otherwise

str1 = "hello";

str2 = "hello2";

str3 = "hello";

var n = str1.localeCompare(str2); //returns -1

logger.info("n: " + n);

var n2 = str1.localeCompare(str3); //returns 0

logger.info("n2: " + n2);

qn
1-Newbie
1-Newbie
(To:gpaillot)

Hi,

By the way, mylocation = "0.0000 : 0.0000"​ is not a comparison (at least two equals ==​, or with a javascript function/method).


Another thing, I believe that the ouput must be named "result". So, you could try:

var result = true;

...

if (...) {

    result = false;

}


In order to know the format of the location, you could log it:

logger.info(me.gpsLocation);

ou

logger.info(String(me.gpsLocation));

So we know what we are comparing (just to be sure about the format).

gpaillot
1-Newbie
(To:qn)

Hi,

I change the name of variable to result asQD N said.

It's better.

But, now my result is still to false whatever if i have a location or not.

I had the logger.info, and there are the values displayed :

location OK : 48.8804802,2.2843372,0.0

location KO : 0.0,0.0,0.0


I change the if condition to      =>  if( mylocation = "0.0,0.0,0.0")

but it's still always False, even with a good location

gpaillot
1-Newbie
(To:qn)

Oh !!! the double = ........ i think i'm tired ...

It's Ok now, TY.


Now, let's update the mashup

The ShowMarker property is not the good property.

It's the ShowSelectionMarker, which display my marker on my map.

Even if i put the ShowMarker to false, the marker displays on the map with the ShowSelectionMarker to True.

It seems not possible to bind a service to the ShowSelectionMarker property....

Any idea ?

qn
1-Newbie
1-Newbie
(To:gpaillot)

There's the property ​"ShowMarkers​" which display all the markers, or nothing.

gpaillot
1-Newbie
(To:qn)

When I check the "ShowMarkers" property and uncheck the "ShowSelectionmarker" property, nothing is displayed : the map is centered on the location but no marker appears.

After testing again, it seems that I did a wrong binding on my G.

The ShowMarkers property works fine if I check it manually - > with my service, no markers displayed

When i test the service directy on each thing, the result is OK.

Probably an issue of binding, it's like the service doesn't run on the good thing, and it doesn't find the location so my If condition is still verified ... and put thr result to false.

I had an input to my service, "name" property of my things, and bind it to the selected name of my GetImplementedThings.

But it's still KO.

qn
1-Newbie
1-Newbie
(To:gpaillot)

By the way, what is the behaviour expected, what do you mean by "reset the map" ?

With ShowMarkers, if the location is not found, nothing will be display. Do you want to display all the location valid, except the invalid one ?

If "reset the map" means center the map to a default location, the invalid location could be replaced by the default location.

gpaillot
1-Newbie
(To:qn)

I want to display all the location valid, except the invalid one.

Today, when i select a thing with an invalid location, just after a thing with a valid location, the GMAP still displays the valid location of the previous object.

I think i was not clear, i want to display location on my map, one by one, depending on the thing selected.

I don't bind "all data" of GetImplementThingWithData on my map.

I bind it with my property gpsLocation of the SelectedRow of the GetProperty service.

qn
1-Newbie
1-Newbie
(To:gpaillot)

I understand that you wanted to "display location on map one by one, depending on the thing selected". But what must happen when a location is invalid ?

gpaillot
1-Newbie
(To:qn)

If a location is invalid : no marker on the map

qn
1-Newbie
1-Newbie
(To:gpaillot)

And which location the map should center if the location chosen is invalid ?

gpaillot
1-Newbie
(To:qn)

the best wil be the default center location (when you add a map without binding location).

Hi all,

Just to keep you inform and thanks for your help : I have opened a ticket to the PTC support, and after reproducing my issue, I've got the confirmation that it is a bug.

mhollenbach
5-Regular Member
(To:gpaillot)

For everyone interested in this topic the coordinates 0,0 are in fact valid but there is a small bug in the GoogleMap Widget that prevents the map from showing a marker at that location (in the center of an ocean). You can see that the map associated with the LocationPicker Widget does in fact render that as a valid point. There is a JIRA submitted against the issue, but in the mean-time, if anyone needs this location to be marked for whatever reason you can always go in and modify Widgets yourself. Keep in mind that we will not support anything that is broken in the process with the Widget, but if you feel comfortable changing it and actually need that coordinate feel free to modify the code.

Top Tags