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 9103333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:36:36+00:00 2026-06-17T01:36:36+00:00

I have successfully set up a Leaflet JS map that uses the Google maps

  • 0

I have successfully set up a Leaflet JS map that uses the Google maps geocoder to pan to a geocoded address. But I am also trying to use “map.fitBounds” to get the appropriate zoom level from the Viewport, but it does not seem to be working. The code I am using is:

map.panTo([results[0].geometry.location.lat(),results[0].geometry.location.lng()]);
   map.fitBounds([[results[0].geometry.viewport.southwest.lat(), results[0].geometry.viewport.southwest.lng()],[results[0].geometry.viewport.northeast.lat(), results[0].geometry.viewport.northeast.lng()]]);

See example here: http://chrismccreath.hostzi.com/geocode_test.html

How can I fix it so that it zooms to the appropriate viewport returned by the google maps geocoder result?

  • 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-17T01:36:37+00:00Added an answer on June 17, 2026 at 1:36 am

    There are no properties like results[0].geometry.viewport.southwest/northeast(I guess you were watching at the network-traffic inside the console, but what you see there will not be passed to the callback-function directly). To get the southwest/northeast use the methods getSouthWest() and getNorthEast() of google.maps.LatLngBounds .

    results[0].geometry.viewport is a google.maps.LatLngBounds-object, but you can’t use it directly in Leaflet.

    You must “convert” it to an array or an Leaflet.LatLngBounds-object.

    This should work:

    map.fitBounds([
                   [results[0].geometry.viewport.getSouthWest().lat(),
                    results[0].geometry.viewport.getSouthWest().lng()],
                   [results[0].geometry.viewport.getNorthEast().lat(),
                    results[0].geometry.viewport.getNorthEast().lng()]
                  ]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully plotted a line between some random co-ordinates on Google Maps for
I have successfully set up a quick test of creating a REST-like service that
I have have successfully set up a list that pulls users from a database
I have successfully implemented the mandelbrot set as described in the wikipedia article, but
I need to set alarm in google calendar via Android app. I have successfully
i have successfully set the httpServletResponse().setHeader(custtype, permanent) but when i try to retrieve it
I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed
I have successfully set up an HgWebDir instance over CGI with Apache, and I
I'm using the the new UIAppearance API and have successfully set the tint color
I have not found any way to successfully set a screen resolution on my

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.