Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/google maps geocoding #665

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

von-development
Copy link

PR Description

Add Google Maps Geocoding API integration to the community package. This integration allows users to convert addresses into geographic coordinates using the Google Maps Geocoding API. The tool is designed to be composable with other Google services and LangChain tools, making it ideal for building location-aware applications.

Key Features:

  • Basic address to coordinates conversion
  • Support for multiple languages
  • Region and viewport biasing
  • Component filtering for precise results
  • Seamless integration with LangChain chains and agents

Integration Opportunities:

  1. Routes Integration: Can be combined with Google Maps Routes API for end-to-end navigation solutions
  2. Places Integration: Works well with Google Places API for location discovery and details
  3. Solar API: Can provide coordinates for solar potential calculations
  4. Sequential Tool Usage: Perfect for multi-step location-based workflows, such as:
    • Address → Coordinates → Route Planning
    • Location Search → Geocoding → Places Details
    • Address Validation → Geocoding → Solar Analysis

Relevant issues

N/A

Type

🆕 New Feature

Changes

  1. Added new files:

    • langchain_google_community/geocoding.py: Main implementation with complete type hints
    • tests/unit_tests/test_geocoding.py: Unit tests
    • tests/integration_tests/test_geocoding.py: Integration tests
    • docs/docs/integrations/geocoding.ipynb: Documentation and examples
  2. Modified existing files:

    • Updated langchain_google_community/__init__.py to expose the new geocoding tools
    • Added googlemaps dependency to the places group in pyproject.toml
  3. Features implemented:

    • GoogleGeocodingAPIWrapper: Direct API interaction
    • GoogleGeocodingTool: LangChain tool integration
    • Support for all major Geocoding API features:
      • Basic address geocoding
      • Component filtering
      • Viewport biasing
      • Region biasing
      • Language support
  4. Type System:

    • Full type hints provided for all wrapper and tool implementations
    • Note: The googlemaps package doesn't provide type stubs (common for many Google API clients)
    • Added appropriate type ignore comments and documentation for third-party dependencies

Testing

  1. Unit Tests:
poetry run pytest tests/unit_tests/test_geocoding.py -v

All tests pass successfully.

  1. Integration Tests:
poetry run pytest tests/integration_tests/test_geocoding.py -v --extended

All tests pass successfully with a valid Google Maps API key.

Note

Requirements:

  1. Users need a Google Maps API key
  2. The Geocoding API must be enabled in their Google Cloud project
  3. Billing must be enabled for the project

Example usage:

from langchain_google_community.geocoding import GoogleGeocodingTool

# Basic usage
tool = GoogleGeocodingTool(api_key="your_api_key")
result = tool.run("1600 Amphitheatre Parkway, Mountain View, CA")
print(result)
# Output: Address: 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA
#         Coordinates: 37.4224764, -122.0842499

@@ -0,0 +1,19 @@
[tool.poetry]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, don't move pyproject files since we have 3 libraries in this repo

Docs: https://developers.google.com/maps/documentation/geocoding/overview

To use this wrapper, you need a Google Maps API key.
You can get one here: https://developers.google.com/maps/documentation/geocoding/get-api-key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a few of examples to a rich docstring, please?



class GoogleGeocodingTool(BaseTool):
"""Tool that queries the Google Maps Geocoding API."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a few of examples to a rich docstring, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants