Get the total number of "Regions / Zones" in which I now live, based on my current location

enter image description here

Suppose we have three hotels: Hotel A (popular within a 1 km radius), Hotel B (popular within a 2 km radius) and Hotel C (popular within a 4 km radius), the car enters and is in a certain position. These hotels (or any other place) are added by us and are custom.

The problem is that I want to find hotels that have popularity / influence in my current location.

And I want this to be done completely with Google Maps . Is it possible ? on Android (optional) ? Please ELI5 .

+8
android google-maps geolocation google-maps-api-3 location
source share
3 answers

The Google Maps API has a computeDistanceBetween function. It "returns the distance, in meters, between the two latitude / longitude coordinates." Circle has the properties of Center and Radius. Therefore, you need to calculate the distance between the center of the circle and the current location. If this is less than the radius of the circle than this means that your current location is inside the circle.

+2
source share

Simplification is the key

Although I understand your goal (to get a list of all the hotels near you), I believe that your explanation has thrown many people into fear. You don’t need to triangulate positions and calculate circle radius - not with the API and Google Maps services.

All you need to know is that you need a solution for front-end, internal, or mobile devices.

Google Maps Website API Web Service (back-end)

The Places API has a very useful feature called "Nearby Places." To quote the documentation for this feature:

A neighborhood search allows you to search for places within a specific area. You can refine your search query by providing keywords or by specifying the type of place you are looking for.

What looks exactly the way you need it, right?

To make a request from the server to the Places API web service by looking for nearby places, you can do the following:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&type=restaurant&name=cruise&key=YOUR_API_KEY 

Remember to change key=YOUR_API_KEY to a valid key field. The above example will look for restaurants within a radius of 500 meters around the place -33.8670522,151.1957362.

There are many options for this, and you can read more about this in the following documentation.

https://developers.google.com/places/web-service/search

JavaScript Maps API with Place Library (front-end)

If you, however, do not have a central server or service to make requests for you, as clients also send requests directly, this is also an option.

In this case, there is a JavaScript API. The JavaScript API is a friendly client API that reuses some features of a web service.

In this case, you can use the JavaScript API in conjunction with the Place Library for it. According to the documentation, this API allows you to perform "Surrounding Search Requests":

Neighborhood Search allows you to search for places in a specified area with a keyword or type

An example of such a request can be seen in a live example in the following link https://developers.google.com/maps/documentation/javascript/examples/place-search

You can read more about the parameters and use of this API and this library in the following documentation https://developers.google.com/maps/documentation/javascript/places#place_search_requests

Google Maps API for Android (Mobile)

From the photo you added, I assume that your application will β€œuse on the go” (possibly a mobile application) or something similar.

In this case, using a web server or website can be cumbersome, because by the time you have an answer from it, the car is already in a different position!

To help you with this, there is also an Android API. To use it, you need:

  • Download and install Android Studio
  • Add Google Play Services Package (contains the APIs you will use)

You can read more about this process here https://developers.google.com/maps/documentation/android-api/start

Regarding code and examples, I highly recommend that you check out this GitHub sample repository https://github.com/googlemaps/android-samples


Our hotels may not appear on Google Maps

If your DeLorean doesn't return you to the second half of the 19th century, or you are stuck on an island with hundreds of Meerkats, poisonous pools and a tiger wondering if you should eat you or not, Google Maps will show you a lot of hotels where you can spend the night.

PS: kudos ++ if someone gets my links: P

Adding Hotels and Places to Google Maps APIs and Services

If this is still not enough, there is still a way to fix it. You can add hotel addresses and locations to Google Maps using one of the following methods:

  • Post a review
  • Use Maps Maker

Post a review

The Send Feedback feature allows you to send reviews to Google data groups for viewing. Once approved, the data is added to the Google database and will be available to all Google customers. You can do this by following the steps described here https://support.google.com/maps/answer/3094045?co=GENIE.Platform%3DDesktop&hl=en

Please note that the process of reviewing your feedback will take some time, so do not expect anything instant!

Use Maps Maker

Alternatively, you can use Maps Maker . This tool allows you to make changes and add information to our services in a more streamlined way.

At first, your changes and suggestions will still be validated, and it usually takes less than two weeks to get something approved.

However, over time, as you claim more and more that you are approved, you gain a reputation, and when you have a lot of reputation, your offers will be largely automatically added.

Before using it, make sure that you look in the list of supported countries .

In addition, if the language is important, you can also consider it by checking the list of supported languages .

I really don't want to add anything to Google Maps

Sometimes the whole business is the information itself, so providing it freely is not an option.

In these cases, you will have your own database, which your services will need to check.

In cases like this, an individual solution is required for your system, but additional information is required in order to propose a few ideas.


Hope this helps!

+1
source share

Your approach should use quick rough calculations without relying on apis, and then using api can be used to improve the user experience.

  • You know the coordinates of the car.
  • You know the coordinates of each of the hotels.
  • Assign popularity weight to each of the hotels based on your criteria or the data you have. for example, a hotel that has more user reviews or transactions or orders will have a higher impact, or if you want to personalize, a hotel that matches the magazine’s budget preferences (based on past data or settings) will have a higher impact. Lets name this popularity value p1, p2..p3, etc.

  • Find all the hotels that are in the threshold range, say, 5 km within the current position of the car. This can be done using a geospatial query in any large storage database (for example, if your hotel points are stored in MySQL or mongodb), or if you use hotel api data, get nearby hotels, or all hotels in this city, and crop them based on from the distance from the current location of the car.

  • For the linear distance between car C and hotels H1, H2 ... use the Haversin formula , this will give you the distance between the car and any hotel along the curvature of the Earth. (The actual distance of the road may vary because the roads are not straight and include turns, etc.). But this will give you a quick approximation of the distances D1 between C and H1, D2 between C and H2, etc ...

  • Now the breakdown of the popularity of P1 ... PN of each hotel based on the distance between Car C and Hotel H. For example, if hotel H1 has a popularity rating of P1 = 90, and hotel H2 has a popularity rating of P2 = 90, but the distance C <---> H1 is 10 km and the distance C <---> H2 is 2 km, then H2 will have a greater impact on the current location compared to H1. A simple formula could be LocationInfluence = PopularityScore/ log(Distance) , you can optimize it based on your usage.

  • Now for the most influential hotels H1, H2, H3 ... use the DistanceMatrix api to find the actual distance, you can also use the google maps direction api for Android or Javascript to show directions to the user, from the place to the hotel.

+1
source share

All Articles