/    Sign up×
Community /Pin to ProfileBookmark

Hi

I have the following code (found on google) which when coupled with an input box (input: postcode), positions a marker on my google map.

My question is, how would I get the page to load with a fixed postcode (i.e. instead of having to input the postcode and clicking submit)

Ultimately, I will be pulling the post from a SQL database.

Regards

<script type=”text/javascript”>

var map;
var localSearch = new GlocalSearch();

var icon = new GIcon();
icon.image = “http://www.google.com/mapfiles/marker.png“;
icon.shadow = “http://www.google.com/mapfiles/shadow50.png“;
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(10, 34);

function usePointFromPostcode(postcode, callbackFunction) {

localSearch.setSearchCompleteCallback(null,
function() {

if (localSearch.results[0])
{
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
callbackFunction(point);
}else{
alert(“Postcode not found!”);
}
});

localSearch.execute(postcode + “, UK”);

}

function placeMarkerAtPoint(point)
{
var marker = new GMarker(point,icon);
map.addOverlay(marker);
}

function setCenterToPoint(point)
{
map.setCenter(point, 3);
}

function showPointLatLng(point)
{
alert(“Latitude: ” + point.lat() + “nLongitude: ” + point.lng());
}

function mapLoad() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById(“map”));

map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(54.622978,-2.592773), 30, G_HYBRID_MAP);
}

}

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}

function addUnLoadEvent(func) {
var oldonunload = window.onunload;
if (typeof window.onunload != ‘function’) {
window.onunload = func;
} else {
window.onunload = function() {
oldonunload();
func();
}
}
}

addLoadEvent(mapLoad);
addUnLoadEvent(GUnload);

</script>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangDec 16.2010 — Run function usePointFromPostcode with the required postcode after mapLoad has loaded
×

Success!

Help @birdy247 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...