Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

Google geocode version 3

I am building one option to find the address through geocode but i am not able to copy/paste the exact code from google or may be i am doing something wrong, it is not showing the map neither the marker:

Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Find Address</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<cfif IsDefined('form.findaddress')>
<cfinvoke component="#request.cfcPath#.googlegeocoder3" method="googlegeocoder3" returnvariable="geocode_answer">       
<cfinvokeargument name="address" value="#form.address#">
<cfinvokeargument name="ShowDetails" value="false">
</cfinvoke>
<cfdump var="#geocode_answer#">
<cfoutput query="geocode_answer">
<script type="text/javascript">    
var geocoder;
  var map;
  var infowindow = new google.maps.InfoWindow();
  var marker;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(40.730885,73.997383);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }

  function codeLatLng() {
    var input = document.getElementById("latlng").value;
    var latlngStr = input.split(",",2);
    var lat = parseFloat(latlngStr[0]);
    var lng = parseFloat(latlngStr[1]);
    var latlng = new google.maps.LatLng(lat, lng);
    if (geocoder) {
      geocoder.geocode({'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (results[1]) {
            map.setZoom(11);
            marker = new google.maps.Marker({
                position: latlng,
                map: map
            });
            infowindow.setContent(results[1].formatted_address);
            infowindow.open(map, marker);
          }
        } else {
          alert("Geocoder failed due to: " + status);
        }
      });
    }
  }
</script>
</cfoutput>
</cfif>
<body onload="initialize()">
<div id="map_canvas" style="width: 320px; height: 480px;"></div>
<div>
<table align="center" width="100%" class="border">
<cfoutput>
  <cfform action="#cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#" method="post">
  <tr><td><caption>Find Latitute & Longitude of Address and Show on Map.</caption></td></tr>
  <tr><td>
    Address&nbsp;:&nbsp;</td>
  </tr>  
  <cfif IsDefined('n')>
        <tr><td align="center" class="darkred"><cfoutput>#ToString(ToBinary(n))#</cfoutput></td></tr>
  </cfif>
  <tr><td>
  <cftextarea name="address" value="#getAddress.address#" rows="5" class="inputstyle" cols="45"></cftextarea>
  </td></tr>
  <tr><td>
    <input type="submit" name="findaddress" value="Find Address!" class="tinyborder" onclick="codeAddress()">
  </td></tr>  
  </cfform>
</cfoutput>
</table>
</div>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Coast Line

ASKER

well i may skipped but what exactly that is i wanna include here