Share Phát Triển Ứng Dụng Đánh Giá Nhà Hàng Trong VB.NET: Sử Dụng ASP.NET và Google Maps API

#Restaurant #evaluation #Application #vb.net #ASP.NET #Google-maps-api

## Phát triển các ứng dụng đánh giá nhà hàng trong VB.NET bằng API ASP.Net và Google Maps

Trong bài viết này, chúng tôi sẽ chỉ cho bạn cách phát triển ứng dụng đánh giá nhà hàng trong VB.NET bằng ASP.NET và API Google Maps.Ứng dụng sẽ cho phép người dùng tìm kiếm các nhà hàng trong khu vực của họ, xem đánh giá về các nhà hàng đó và gửi đánh giá của riêng họ.Chúng tôi cũng sẽ chỉ cho bạn cách sử dụng API Google Maps để hiển thị bản đồ các nhà hàng trong khu vực người dùng.

### Điều kiện tiên quyết

Để làm theo với hướng dẫn này, bạn sẽ cần những điều sau đây:

* Một kiến thức làm việc của vb.net
* Một kiến thức làm việc của ASP.NET
* Khóa API bản đồ Google bản đồ

### Bắt đầu

Bước đầu tiên là tạo một dự án ứng dụng web ASP.NET mới.Khi dự án được tạo, hãy thêm một biểu mẫu web mới vào dự án.Trong biểu mẫu Web, thêm các tài liệu tham khảo sau:

* `System.Web.Service`
* `System.Web.Script.Service`
* `Google.maps.service`

Chúng tôi cũng sẽ cần thêm một tham chiếu đến thư viện JavaScript API của Google Maps.Để thực hiện việc này, nhấp chuột phải vào thư mục `TÀI LIỆU THAM KHẢO trong Giải pháp Explorer và chọn` Thêm tham chiếu`.Trong hộp thoại Thêm tham chiếu, nhấp vào nút `browse` và điều hướng đến vị trí sau:

`` `
https://maps.googleapis.com/maps/api/js?libries=places&key= <Your_API_KEY>
`` `

Thay thế `<Your_API_KEY>` bằng khóa API Google Maps của riêng bạn.

### Tạo giao diện người dùng

Bước tiếp theo là tạo giao diện người dùng cho ứng dụng.Giao diện người dùng sẽ bao gồm một thanh tìm kiếm, danh sách các nhà hàng và bản đồ của các nhà hàng.

Để tạo thanh tìm kiếm, hãy thêm điều khiển `textbox` vào biểu mẫu web.Trong trình xử lý sự kiện `textbox` của` textChanged`, thêm mã sau:

`` `
Dim SearchResults như Danh sách (của Nhà hàng)

'Nhận kết quả tìm kiếm từ API Google Maps.
searchResults = getRestaurantsFromGoogle (txtSearch.text)

'Xóa danh sách các nhà hàng.
lstrestaurant.items.clear ()

'Thêm kết quả tìm kiếm vào danh sách các nhà hàng.
Đối với mỗi nhà hàng ở SearchResults
lstrestaurant.items.add (nhà hàng)
Kết thúc cho
`` `

Chức năng `getRestauRsFromGoogle` lấy chuỗi tìm kiếm làm đầu vào của nó và trả về một danh sách các nhà hàng phù hợp với chuỗi tìm kiếm.Chức năng được thực hiện như sau:

`` `
Chức năng GetRestauRsFromGoogle (searchString as String) như danh sách (của nhà hàng)

'Tạo máy khách API Google Maps mới.
Máy khách Dim dưới dạng GoogLemapsClient mới ()

'Tạo yêu cầu API địa điểm mới.
Yêu cầu Dim dưới dạng placessarchrequest mới ()

'Đặt vị trí tìm kiếm thành vị trí hiện tại của người dùng.
request.location = client.CurrentLocation

'Đặt bán kính tìm kiếm thành 10 dặm.
yêu cầu.radius = 10

'Đặt loại tìm kiếm cho nhà hàng.
request.type = "Nhà hàng"

'Đặt truy vấn tìm kiếm thành chuỗi tìm kiếm.
request.Query = searchString

'Thực hiện yêu cầu API địa điểm.
Kết quả mờ như danh sách (vị trí) = client.places.search (Yêu cầu)

'Tạo một danh sách mới các nhà hàng.
Nhà hàng dimer như danh sách mới (của nhà hàng)

'Thêm kết quả vào danh sách các nhà hàng.
Đối với mỗi kết quả trong kết quả
Nhà hàng mờ như nhà hàng mới ()

nhà hàng.name = result.name
nhà hàng.rating = result.rating
nhà hàng.Vicinity = result.Vicinity

nhà hàng.add (nhà hàng)
Kết thúc cho

'Trả lại danh sách các nhà hàng.
Trở lại nhà hàng
Hàm cuối
`` `

Lớp `Nhà hàng` là một lớp đơn giản đại diện cho một nhà hàng.Lớp có các thuộc tính sau:

*
=======================================
#Restaurant #evaluation #Application #vb.net #ASP.NET #Google-maps-api

## Developing Restaurant Evaluation Applications in VB.NET Using ASP.NET and Google Maps API

In this article, we will show you how to develop a restaurant evaluation application in VB.NET using ASP.NET and the Google Maps API. The application will allow users to search for restaurants in their area, view reviews of those restaurants, and submit their own reviews. We will also show you how to use the Google Maps API to display a map of the restaurants in the user's area.

### Prerequisites

To follow along with this tutorial, you will need the following:

* A working knowledge of VB.NET
* A working knowledge of ASP.NET
* A Google Maps API key

### Getting Started

The first step is to create a new ASP.NET Web Application project. Once the project is created, add a new Web Form to the project. In the Web Form, add the following references:

* `System.Web.Services`
* `System.Web.Script.Services`
* `Google.Maps.Services`

We will also need to add a reference to the Google Maps API JavaScript library. To do this, right-click on the `References` folder in Solution Explorer and select `Add Reference`. In the Add Reference dialog box, click on the `Browse` button and navigate to the following location:

```
https://maps.googleapis.com/maps/api/js?libraries=places&key=<YOUR_API_KEY>
```

Replace `<YOUR_API_KEY>` with your own Google Maps API key.

### Creating the User Interface

The next step is to create the user interface for the application. The user interface will consist of a search bar, a list of restaurants, and a map of the restaurants.

To create the search bar, add a `TextBox` control to the Web Form. In the `TextBox` control's `TextChanged` event handler, add the following code:

```
Dim searchResults As List(Of Restaurant)

' Get the search results from the Google Maps API.
searchResults = GetRestaurantsFromGoogle(txtSearch.Text)

' Clear the list of restaurants.
lstRestaurants.Items.Clear()

' Add the search results to the list of restaurants.
For Each restaurant In searchResults
lstRestaurants.Items.Add(restaurant)
End For
```

The `GetRestaurantsFromGoogle` function takes a search string as its input and returns a list of restaurants that match the search string. The function is implemented as follows:

```
Function GetRestaurantsFromGoogle(searchString As String) As List(Of Restaurant)

' Create a new Google Maps API client.
Dim client As New GoogleMapsClient()

' Create a new Places API request.
Dim request As New PlacesSearchRequest()

' Set the search location to the user's current location.
request.Location = client.CurrentLocation

' Set the search radius to 10 miles.
request.Radius = 10

' Set the search type to restaurant.
request.Type = "restaurant"

' Set the search query to the search string.
request.Query = searchString

' Execute the Places API request.
Dim results As List(Of Place) = client.Places.Search(request)

' Create a new list of restaurants.
Dim restaurants As New List(Of Restaurant)

' Add the results to the list of restaurants.
For Each result In results
Dim restaurant As New Restaurant()

restaurant.Name = result.Name
restaurant.Rating = result.Rating
restaurant.Vicinity = result.Vicinity

restaurants.Add(restaurant)
End For

' Return the list of restaurants.
Return restaurants
End Function
```

The `Restaurant` class is a simple class that represents a restaurant. The class has the following properties:

*
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top