Find an optimal method to accurately obtain the geographical location of a mobile phone webpage (requirement: calculate the distance from the user to the restaurant, and limit the delivery range before ordering)

Source: Internet
Author: User
Because the project needs to calculate nearby restaurants based on the geographical location of the current user, and sort the restaurants by distance, and only place orders in restaurants within the delivery range. I want to know if there is any map API to help me implement this function. What I think of now is: 1: Get the current user's accuracy...

Because the project needs to calculate nearby restaurants based on the geographical location of the current user, and sort the restaurants by distance, and only place orders in restaurants within the delivery range.

I want to know if there is any map API to help me implement this function.

What I think of now is:
1: Obtain the longitude and latitude of the current user,
2: Each of our dining table also has a latitude and longitude field information, and there is a distribution radius within How many kilometers,
3: query the restaurants that can order meals based on the user's latitude and longitude, and calculate the distance,

The current problem is how to implement step 1 and step 3?

Add another question:

Step 2: in fact, the distribution radius is relatively simple. It is best to have a distribution range and draw an area on the map. But it is more complicated. I just thought this way, I still don't know how to implement it. (The last time I asked a similar question, some people said that the distance between computing needs to be done by a dedicated map location computing server. Isn't that too high a threshold, I would like to see if there is any convenient map API that can be implemented in part, and then implemented through the PHP + MYSQL Program)

Hope you can give me some advice. Thank you! ^_^

PS: If you can use the API to implement it, you can also want to know the principle.

Reply content:

Because the project needs to calculate nearby restaurants based on the geographical location of the current user, and sort the restaurants by distance, and only place orders in restaurants within the delivery range.

I want to know if there is any map API to help me implement this function.

What I think of now is:
1: Obtain the longitude and latitude of the current user,
2: Each of our dining table also has a latitude and longitude field information, and there is a distribution radius within How many kilometers,
3: query the restaurants that can order meals based on the user's latitude and longitude, and calculate the distance,

The current problem is how to implement step 1 and step 3?

Add another question:

Step 2: in fact, the distribution radius is relatively simple. It is best to have a distribution range and draw an area on the map. But it is more complicated. I just thought this way, I still don't know how to implement it. (The last time I asked a similar question, some people said that the distance between computing needs to be done by a dedicated map location computing server. Isn't that too high a threshold, I would like to see if there is any convenient map API that can be implemented in part, and then implemented through the PHP + MYSQL Program)

Hope you can give me some advice. Thank you! ^_^

PS: If you can use the API to implement it, you can also want to know the principle.

You can call the AMAP api to obtain the latitude and longitude of a restaurant, and then use navigator. geolocation of h5 to obtain the latitude and longitude of the current user, and then calculate the distance.

In step 1, you can use HTML5 APIs like the first floor to obtain the longitude and latitude.
In step 3, you can find a map, such as the developer documentation of Baidu map and AMAP. The corresponding method will be available and you can call it directly.
Here are some links for you to see.
HTML5 location
HTML5 Geolocation)
Baidu map API
AMAP APIs

If you directly obtain the user's latitude and longitude (provided by the interface), then calculate the distance based on the latitude and longitude of your restaurant

Currently, we use the Api to obtain the geographical location of users.

Distance calculation can be calculated using the mysql Earth radius mentioned above, but the query speed is relatively slow ..

Currently, the project uses the Geohash algorithm to calculate the distance, or refer to this solution of a certain group for a document.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.