Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 24th, 2010, 01:49 AM
Registered User
 
Join Date: Oct 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Google maps Geocode

I read Imar's book - beginning Asp.net 3.5. It is a great book.
I then started building a website but i'm having issues with google maps javascript. I was trying out some sample code from Google's training but i keep getting the error on firebug - "google.maps.Geocoder is not a constructor"
for the line: geocoder = new google.maps.Geocoder();

I searched for the error online and found a few posting recommending - google.setOnLoadCallback() - to be used. But when i used that i seem to be getting more errors.

Below is the code for the entire page. Please let me know what's causing the error.

Thank you!

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Maps2.aspx.cs" Inherits="Trial_Maps2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;
key=ABQIAAAAJufm5IbqOx3oHcWCrkcpPZyfNiLPHlJijQMANFPQ" 
type="text/javascript"></script>
    <script type="text/javascript">

  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}



  function codeAddress() {
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
}
    
  </script>
</head>

<body onload="initialize()">
 <div id="map_canvas" style="width: 320px; height: 480px;"></div>
  <div>
    <input id="address" type="text" value="Sydney, NSW"/>
    <input type="button" value="Encode" onclick="codeAddress()"/>
  </div>
</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
com.google.android.maps library unavailable lz1234 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 1 June 7th, 2009 10:18 AM
Hacked Bills Google Maps Code ramone_johnny Classic ASP Basics 5 August 5th, 2008 10:11 PM
Bills Whiz Bang Google Maps ramone_johnny Classic ASP Basics 2 August 1st, 2008 07:23 PM
Google Maps JS in ASPX page error kingroon ASP.NET 2.0 Basics 0 December 7th, 2007 09:52 AM
XSL, Javascript and Google maps.. tomharding XSLT 2 March 14th, 2007 06:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.