This project is a Java-based backend service for finding nearby places using Google Maps API. The application is built using Spring Boot and follows an N-layered architecture to ensure modularity, scalability, and maintainability.
Deployed to https://web-production-8958.up.railway.app
Sample Query https://web-production-8958.up.railway.app/api/places/search?latitude=40.9905539&longitude=29.0195239&radius=500
Swagger Page : https://web-production-8958.up.railway.app/swagger-ui/index.html#/place-controller/searchNearby
- Fetches nearby places based on latitude, longitude, and radius.
- Caches the results to a database to avoid redundant API calls.
- Uses Google Places API for data retrieval.
- Provides RESTful endpoints for querying places.
- Java 8+
- Spring Boot
- Hibernate
- MySQL
- Feign Client
- Swagger for API documentation
The N-layered architecture divides the application into distinct layers, each responsible for a specific aspect of the application. This approach enhances modularity, making the application easier to manage and scale.
The Presentation Layer handles the HTTP requests and responses. It includes the controllers that expose the RESTful endpoints for the API.
@RestController
@RequestMapping("/api/places")
public class PlaceController {
@Autowired
private PlaceService placeService;
@GetMapping("/search")
public DataResult<List<PlaceResponse>> searchNearbyPlaces(
@RequestParam double latitude,
@RequestParam double longitude,
@RequestParam int radius) {
return placeService.getNearbyPlaces(latitude, longitude, radius);
}
}
The Service Layer contains the business logic of the application. It processes the requests from the controllers and interacts with the Data Access Layer to fetch or persist data.
@Service
public class PlaceService {
@Autowired
private PlaceRepository placeRepository;
@Autowired
private GooglePlacesClient googlePlacesClient;
public DataResult<List<PlaceResponse>> getNearbyPlaces(double latitude, double longitude, int radius) {
// Business logic to fetch places
}
}
The Data Access Layer interacts with the database. It contains repository classes that perform CRUD operations on the database entities.
@Repository
public interface PlaceRepository extends JpaRepository<Place, Long> {
// Custom query methods
}
The Integration Layer handles communication with external services, such as the Google Places API. This layer uses Feign Client for making HTTP calls to external APIs.
@FeignClient(name = "googlePlacesClient", url = "${google.places.api.url}")
public interface GooglePlacesClient {
@GetMapping
GooglePlacesResponse getPlaces(@RequestParam("location") String location,
@RequestParam("radius") int radius,
@RequestParam("key") String apiKey);
}
-
Clone the repository:
git clone https://github.com/yusufferdogan/GoogleMaps-NearBy-Places-Api.git cd GoogleMaps-NearBy-Places-Api
-
Set up MySQL database:
- Create a database named
nearby_places
. - Update the
application.properties
file with your MySQL database credentials.
- Create a database named
-
Run the application:
./mvnw spring-boot:run
-
Access the API documentation:
- Open https://web-production-8958.up.railway.app/swagger-ui/index.html#/place-controller/searchNearby in your browser to view the Swagger UI documentation.
Contributions are welcome! Please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.
For more information, visit the project repository.
Columns: latitude, longitude, radius Primary Key: Combination of latitude, longitude, and radius Description: This table stores the details of location-based requests made by users, including the latitude, longitude, and the search radius. place Table:
Columns: id (Primary Key), latitude, longitude, name, place_id (unique), rating, vicinity, photo
Primary Key: id
Unique Constraint: place_id
Description: This table stores details about places returned from the Google Places API, such as their geographical coordinates, name, unique place identifier, rating, vicinity, and photo reference.
place_request_response Table:
Columns: place_id, place_request_latitude, place_request_longitude, place_request_radius
Primary Key: Combination of place_id, place_request_latitude, place_request_longitude, place_request_radius
Foreign Keys:
place_request_latitude, place_request_longitude, place_request_radius references place_request (latitude, longitude, radius)
place_id references place (id)
Description: This table represents the many-to-many relationship between place_request and place. Each entry links a specific place to a specific request.
Relations:
place_request to place_request_response:
A one-to-many relationship where each request can have multiple associated responses.
place to place_request_response:
A one-to-many relationship where each place can be associated with multiple requests.