Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:03:12+00:00 2026-06-15T13:03:12+00:00

I was using geocode service of Google Maps Version 2 the Javascript API. https://developers.google.com/maps/documentation/javascript/v2/reference

  • 0

I was using geocode service of Google Maps Version 2 the Javascript API.
https://developers.google.com/maps/documentation/javascript/v2/reference
However google decided not to support his anymore.

Note: The Google Maps JavaScript API Version 2 has been officially
deprecated as of May 19, 2010. The V2 API will continue to work until
May 19, 2013. We encourage you to migrate your code to version 3 of
the Maps JavaScript API.

So how can I geocode in google maps version 3 javascript api with zoom?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:03:13+00:00Added an answer on June 15, 2026 at 1:03 pm

    To zoom the map to best show the results of the geocoding operation, you can use the google.maps.Map fitBounds method with the viewport property of the result:

    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
                });
            if (results[0].geometry.viewport) 
              map.fitBounds(results[0].geometry.viewport);
          } else {
            alert("Geocode was not successful for the following reason: " + status);
          }
        });
      }
    

    code snippet:

    var geocoder, map, marker;
    
    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);
          if (marker && marker.setMap) marker.setMap(null);
          marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
          });
          if (results[0].geometry.viewport)
            map.fitBounds(results[0].geometry.viewport);
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
    
    function initialize() {
      geocoder = new google.maps.Geocoder();
      map = new google.maps.Map(
        document.getElementById("map_canvas"), {
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });
      google.maps.event.addDomListener(document.getElementById('btn'), 'click', codeAddress);
      codeAddress();
    
    }
    google.maps.event.addDomListener(window, "load", initialize);
    html,
    body,
    #map_canvas {
      height: 100%;
      width: 100%;
      margin: 0px;
      padding: 0px
    }
    <script src="https://maps.googleapis.com/maps/api/js"></script>
    <input id="address" value="Palo Alto, CA" />
    <input id="btn" value="Geocode" type="button" />
    <div id="map_canvas"></div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Google's geocding service as documented here ( http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding ) I'm trying to
I'm using http://maps.google.com/maps/geo ? web service to geocode some addresses. The problem I have
I've seen many posts about the Google Geocoding API, described here: http://code.google.com/apis/maps/documentation/geocoding/ but none
I have small database of business and their addresses. Using the Google Geocode API
I am using the following method to reverse geocode a google maps latlng: [GClientGeocoder.getLocations(address:String,
I have a requirement to geocode data using Google's geocoding service. Google's geocoding services
I'm using Google Maps API on my web page. I'm try to add multiple
I'm using Google Maps and Google Geocoding service for my location service application. I
I am using the Google Maps places API v3 to return a number of
I'm searching for a way to geocode venues with google maps. The Geocoder API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.