﻿var map = null;  
var numberOfResults = 1; 
var showResult = true;
var createResult = true;
var address = null;
var postcode = null;
var centerLatLng = null;
var disambiguation = false;
                          
                          
function callback(a,b,foundPlaces,d,e)
{
    centerLatLng = map.GetCenter();                                                        
    map.SetCenterAndZoom(centerLatLng,15);                                                        
    var place = null;
    var shape =null;                            
    //Check we found atleast 1 place
    //If we did stick the pin in
    if(foundPlaces.length >=1)
    {
    //Get the first place found
    place = foundPlaces[0]
    //Create a Shape (Pushpin)
    shape = new VEShape(VEShapeType.Pushpin, place.LatLong); 
    map.AddShape(shape);                               
    }                                                        
}                                                       

function GetMap()
{
    map = new VEMap('map');                             
    map.SetDashboardSize(VEDashboardSize.Tiny);
    map.LoadMap(null,15,VEMapStyle.Road,false,VEMapMode.Mode2D,false,0,null);                                                                                                                  
}                                
function FindLoc(address,postcode)
{
    try
    {
        map.Find(null,address + ", " + postcode + ",UK",null,null,0,numberOfResults,showResult,createResult,disambiguation,true,callback);                                                                                                                                
    }
    catch(e)
    {
        alert(e.message);
    }
}   
                                                   
function onLoad()
{            
    //Get the Address from id'd elements on the page
    address = document.getElementById("Address").innerText;
    postcode = document.getElementById("Postcode").innerText;
    GetMap();
    FindLoc(address,postcode);                                    
}
