Jump to content


Photo

Mobile Google Maps Global Variable Access

global

  • Please log in to reply
5 replies to this topic

#1 andyhill

andyhill

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 346 posts
  • LocationMelbourne Australia

Posted 28 January 2018 - 10:52 PM

I use several google map markers on initial map presentation and all paint correctly.

 

After initializing with the default markers, the user can then request a marker's position to be updated.

 

Therefore before any marker updates can take place I want to verify if there are previous markers already on the map, if so then I need to remove the old marker in order to paint the markers new position. 

 

In my code below the alert(''new''); always fires telling me that markers is not global - how can I accomplish this - thanks in advance.

 

// Set Global Variable


procedure TGPSmForm.UnimFormCreate(Sender: TObject);
begin
  UniSession.AddJS('var markers = [];');
end;
 
...
 
      UniSession.AddJS(
                       'if (markers == null) '+
                       '{ '+
                       '  var markers = []; '+
                       '  alert(''new''); '+
                       '} '+
 
                       'var gm = googleMap; '+
                       'if (typeof gm == "object") '+
                       '{ '+
 
                       '  for (var i = 0; i < markers.length; i++) '+
                       '  { '+
                       '    markers[i].setMap(null); '+
                       '    alert(''for loop''); '+
                       '  } '+
 
 
...
 
 

                       '  markers.push(manmarker); '+
 
 

 


  • 0

Andy


#2 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 4969 posts

Posted 29 January 2018 - 04:10 AM

"Solutions":

uniVars.markers;
YourObject.markers;

  • 0

#3 andyhill

andyhill

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 346 posts
  • LocationMelbourne Australia

Posted 29 January 2018 - 05:19 AM

Perhaps I miss understood you.

 

procedure TGPSmForm.UnimFormCreate(Sender: TObject);
begin
  UniSession.AddJS('var uniVars.markers = [];');
end;
 
procedure TGPSmForm.UnimHTMLFrame1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
 
...
 
      UniSession.AddJS('var gm = googleMap; '+
                       'if (typeof gm == "object") '+
                       '{ '+
 
                       '  for (var i = 0; i < uniVars.markers.length; i++) '+
                       '  { '+
                       '    uniVars.markers[i].setMap(null); '+
                       '  } '+
 
                       '  var myLatLng = {lat: '+LatStr+', lng: '+LngStr+'}; '+
                       '  var imageman = ''man.png'';'+
                       '  var manmarker = new google.maps.Marker '+
                       '  ( '+
                       '    { '+
                       '      position: myLatLng, '+
                       '      map: gm, '+
                       '      icon: imageman '+
                       '    } '+
                       '  ); '+
 
                       '  uniVars.markers.push(manmarker); '+
                       '  gm.resizeWindow; '+
 
                       '} '
 
                      );
 
Would you please show in code - thanks.

  • 0

Andy


#4 Delphi Developer

Delphi Developer

    Advanced Member

  • Moderators
  • 4969 posts

Posted 29 January 2018 - 06:00 AM

 

Perhaps I miss understood you.

 

procedure TGPSmForm.UnimFormCreate(Sender: TObject);
begin
  UniSession.AddJS('var uniVars.markers = [];');
end;

 

 

Without var:

UniSession.AddJS('uniVars.markers = [];');

  • 0

#5 andyhill

andyhill

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 346 posts
  • LocationMelbourne Australia

Posted 29 January 2018 - 06:25 AM

Perfect - thank you.

 

I am using title to distinguish markers however I do not want labels painted.

 

How would you tag markers so as to know one from another without using title ?


  • 0

Andy


#6 andyhill

andyhill

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 346 posts
  • LocationMelbourne Australia

Posted 29 January 2018 - 11:34 PM

Because I did not want labels associated with the Icon Marker I have used the zIndex as a tag for selective deleting.


  • 0

Andy





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users