Alpha Video Training
Results 1 to 6 of 6

Thread: Center Google Map dynamically

  1. #1
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default Center Google Map dynamically

    See attached image.

    Google Center Map.gif

    I need to center the map on the users zip code using a session variable or other method. The field does not accept a variable. Is there a way?

  2. #2
    Member compuaid's Avatar
    Real Name
    Brad Weaver
    Join Date
    Aug 2007
    Location
    Ottawa, ON
    Posts
    386

    Default Re: Center Google Map dynamically

    It's not ideal but what I do is set a variable and then add the following code to the onDialogInitialize Server-side event where the map control is being used (assuming the map control is named M1 and my global variable containing the address is "addr"):

    if variable_exists("addr")
    e.javascript = "var a1 = '" + addr + "'; " ' Set initial location to address if specified
    else
    e.javascript = "var a1 = '151 Springtown Road, Toronto ON, Canada';" ' Set a default initial location if none specified in call (addr is undefined)
    end if
    e.javascript = e.javascript+"var m1 = {dialog.Object}.getControl('m1'); m1.setCenter(a1);" ' Sets the center location
    e.javascript = e.javascript+" var settings={ title: a1 }; m1.addMarker('add1',a1, settings);" ' and adds a marker
    The reason I say this is not ideal is that you will still get a quick flash of the Burlington map and then be immediately centered on your location contained in the variable "ADDR" with a marker at the address. Ideally what we should have exposed is the property of the M1 map control to set the initial center without having to call setCenter which results in a second call to the Google API. This works if you are using the new Map control in a Dialog 2 component. I haven't tried this using the Google Maps web component. There are arguments you can access in the Google Maps web component for CenterLat, CenterLong and CenterAddress but I haven't figured out quite how to use those yet. It seems like they would be a logical choice for doing what you're wanting to attempt if only they were documented!

    Suggestions Alpha support?
    Last edited by compuaid; 04-24-2012 at 11:02 AM.
    Brad Weaver, President
    ComputerAid International
    Ottawa ON Canada
    Versailles KY USA
    www.compuaid.com

  3. #3
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default Re: Center Google Map dynamically

    Thanks Brad. At least there is hope.

  4. #4
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,672

    Default Re: Center Google Map dynamically

    Peter if you use the sensor for centering - the map will sense (centre) where it is even not in a mobile device - it works client-side in the browser on desktop. - Some browsers will ask permission some don't.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

  5. #5
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default Re: Center Google Map dynamically

    Thanks for the tip Pete. Right now that web site is off line, But I'll test that when we put it back up. Just not sure we can tolerate the browser asking permission.

  6. #6
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,672

    Default Re: Center Google Map dynamically

    Happens in Firefox - it remembers (I think).. anyhow have a go.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

Similar Threads

  1. Center MAP with lat , lng
    By tsekg in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 03-13-2012, 08:25 AM
  2. Google Map Error
    By Peter.Greulich in forum Application Server Version 11 - Web/Browser Applications
    Replies: 19
    Last Post: 02-07-2012, 11:36 PM
  3. Google Map Markers
    By Pat Bremkamp in forum Application Server Version 11 - Web/Browser Applications
    Replies: 9
    Last Post: 01-23-2012, 06:05 PM
  4. Google map integration
    By Claire Shuttleworth in forum Archived Wishlist
    Replies: 1
    Last Post: 10-21-2010, 04:42 PM
  5. Google Map not showing
    By ChristJC in forum Application Server Version 9 - Web/Browser Applications
    Replies: 3
    Last Post: 03-06-2010, 01:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •