close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

code to move map to new center

Thread began 4/15/2010 12:17 pm by roger391472 | Last modified 3/14/2014 9:02 am by Jason Byrnes | 2471 views | 6 replies |

roger391472

code to move map to new center

I'm working on a map that displays the entire US on open but then when a "state" link is clicked I want it to pan and zoom to the state that was clicked. I've listed the state centers and their respective zoom levels in an xml file called states.xml This is my first use of javascript and GoogleMaps and I'm having trouble figuring this out.

Here's the link to the site: index.php To see the page I'm working on click on the "Tracks" button at the top of the page. There's also a details page if you click on one of the states and then click on one of the tracks. It's track_details.php but I used ProMaps on it and everything is working perfectly in it. When I tried to use the ProMaps on the race_track_directory.php page though I couldn't get it to work. It seemed to be a code conflict with the recordset on that page. I had to take out the WHERE statement to get it to work and then of course the "states" links and my repeating region for the tracks didn't work. I tried using DA Search, a second recordset and concatenating the WHERE statement but couldn't anywhere with it. So now I've gone back to just the regular GoogleMaps API code and I'm outputting the xml with phpsqlajax_genxml.php All of the xml is working fine for the markers.

Currently I'm getting a "trkstate is not defined" in Firebug and the map isn't moving at all.

Here's the javascript that I'm trying to use. The gup function was a function that I found in a search that is supposed to pull the url parameter.

function gup( trkstate )
{
trkstate = trkstate.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+trkstate+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];

GDownloadUrl("states.xml", function(data, responseCode) {
alert(data);
});

var trkstate_param = gup( 'trkstate' );

function animate() {
map.panTo(new GLatLng("stlat", "stlong"));
var getstate = xml.documentElement.getElementsByTagName("statezoom");
var panpoint = new GLatLng(parseFloat(statezoom.getAttribute("stlat")),
parseFloat(statezoom.getAttribute("stlong")));
}
}

I'd really appreciate it if someone could head me in the right direction. Let me know if you need me to post any of the code or anything.

Thanks in advance.

Sign in to reply to this post

Jason ByrnesWebAssist

try changing:

php:
<body onload="initialize(); gup(); MM_preloadImages('plugins/images/btn_magazine_on.gif','plugins/images/btn_tracks_on.gif')" onunload="GUnload()">




to:

php:
<body onload="initialize(); gup('<?php echo((isset($_GET['trkstate']))?$_GET['trkstate']:""); ?>'); MM_preloadImages('plugins/images/btn_magazine_on.gif','plugins/images/btn_tracks_on.gif')" onunload="GUnload()">
Sign in to reply to this post

roger391472

Hi Jason,

Thanks, that got rid of the error but the map still isn't panning to the state center when a state is clicked. Any ideas why that isn't working? I did a document.write and it did confirm that it's finding the states.xml.

I'm just so new to javascript though that I don't have any idea if I've got that even close to being written correctly.

I'll upload the page with the new code in it.

Sign in to reply to this post

Jason ByrnesWebAssist

OK, actually, I think I see the problem.

there are a few things going on.

1) the gup() function should be called inside the initialize function, not in the body onLoad.

2) Do not use a separate animate() function.

the code to set the maps center should be part of the initialize function.

the code flow of the initialize function should be:

1) Draw the map
2) cal the gup() funtion to return the trkstate query string variable
3) get the lat, long and zoom level from your xml page and reset the maps scenter point.

Sign in to reply to this post

roger391472

Hi Jason,

Great thanks, I'll work on moving everything.

Roger

Sign in to reply to this post

Yummy

Google map APIs: how to get my location then show nearby restaurants from restaurants stored in my database

hi guys,
I need a tutorial for this kind of application:
- an app that gets my location and shows it with a marker on Google map.
- this app should have a button and when I click on it:
It select from my database nearest restaurants (within any range, maybe 1 miles) and show them with markers on the map.
=>of course restaurants are stored in the database with their names and coordinates (latitude & longitude).

If anyone ever seen any tutorial to do such an app, please tell me.
Thx

Sign in to reply to this post

Jason ByrnesWebAssist

in pro maps, you can use a recordset to display addresses.

for what you are describing, you would need to do a radius search of the database:
http://our-knowledge-base.blogspot.com/2012/04/how-to-search-within-defined-radius.html

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...