The best way to get a precise geographic location for a mobile Web page (requirement: Calculate the distance from the user to the restaurant, and limit the range of delivery to order meals)

Source: Internet
Author: User

Because the project needs to calculate the nearby restaurant according to the current user's location and sort the restaurant according to the distance, and can only place orders in the restaurant within the distribution range.

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

What I'm thinking now is this:
1: Get the accurate latitude and longitude of the user's current location,
2: Each of our restaurant tables also has a latitude and longitude field information, and there is a distribution radius within a few kilometers,
3: According to the latitude and longitude of the user to find a restaurant can order, and calculate the distance,

The current problem is step 1, step 3, how to achieve?

Add one more question:

Step 2 In fact, the distribution radius is a relatively simple practice, it is best to have a distribution range, can draw an area on the map out, but this is more complex, I just this idea, still do not know can be achieved by how. (last time asked and this similar question, some people say that the calculation distance needs a special map location computing server to do, then this is not the threshold is too high, I think there is no more convenient map API can be implemented in part, and then through the program Php+mysql implementation)

I hope the great God help me, thank you ^_^

PS: If the API can be implemented can also, want to know the principle

Reply content:

Because the project needs to calculate the nearby restaurant according to the current user's location and sort the restaurant according to the distance, and can only place orders in the restaurant within the distribution range.

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

What I'm thinking now is this:
1: Get the accurate latitude and longitude of the user's current location,
2: Each of our restaurant tables also has a latitude and longitude field information, and there is a distribution radius within a few kilometers,
3: According to the latitude and longitude of the user to find a restaurant can order, and calculate the distance,

The current problem is step 1, step 3, how to achieve?

Add one more question:

Step 2 In fact, the distribution radius is a relatively simple practice, it is best to have a distribution range, can draw an area on the map out, but this is more complex, I just this idea, still do not know can be achieved by how. (last time asked and this similar question, some people say that the calculation distance needs a special map location computing server to do, then this is not the threshold is too high, I think there is no more convenient map API can be implemented in part, and then through the program Php+mysql implementation)

I hope the great God help me, thank you ^_^

PS: If the API can be implemented can also, want to know the principle

You can call the map's API to get the latitude and longitude of the restaurant, then use the H5 navigator.geolocation to get the latitude and longitude of the current user, and then calculate the distance.

Step 1, you can use the HTML5 API to get latitude and longitude like the 1 floor.
Step 3, you can find a map, such as Baidu Map, the developer documentation of the gold map, there will be a corresponding method, directly call on it can be
Give you a few links you can see
HTML5 Location
HTML5 geolocation (geo-location)
Baidu Map API
German Map API

If you get the latitude and longitude of the user directly (the interface is provided), then calculate the distance based on the latitude and longitude of your restaurant.

Our current approach is to get the user's location through the API

Distance calculation can be calculated using the MySQL earth radius, but this query is slower.

The current project uses but Geohash algorithm to calculate the distance. or refer to the program of a regiment for a mission 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.