Jump to content

Recommended Posts

Hi, 

 

First of all i want to apologize if i posted this in the wrong section. I am not really sure where it will go. So Mods, if u feel this thread belongs elsewhere, please shift it there. :)

 

Now my problem:

 

I am making this interface for shoppers where they can input their shopping list and the program will return a map with the shortest route to get the stuff they want.

I dont know how to generate a map using PHP. I have a basic layout of the map, but how do i mark the locations on the map and then output it to the user as a single image?

 

 

Regards,

Makrand

Edited by makrand1996
Link to comment
https://forums.phpfreaks.com/topic/281889-how-to-make-a-map-of-my-own/
Share on other sites

Use google maps. And simply place Maker's on the map. It's also possible to get the directions between two Maker's.

 

I want to make a map that shows the inside of a store, not between two locations.

To clarify, here is an example:

 

Suppose I am going to the grocer's and i want to buy bread, cheese and milk. So i can open up the website of the grocer's and get a map showing where those items are located inside his store and also gives me the fastest route so that i spend a minimum amount of time looking for the stuff and where it is located.

 

I dont see how google maps can help me do that. Could you please show me how? I know how to show directions from the user's location to a specific coordinate. But how do I solve the above problem?

 

Regards,

Makrand

Edited by makrand1996

Show you how? This would be a pretty complex project that would require quite a bit of time and energy. Especially depending on what you mean by "inside the store". If you mean like 3d imaging and being able to view and navigate around the store that would be expensive and complicated. It would be easiest just to take your own dimensions of the store get a drawing utility and draw a map. Then store the coordinates of the items in a database. Then you can run some algorithms to find the quickest route and locate items.

  • Solution

Create a database table with 3 columns: one for item, another for X coordinate, and another for Y coordinate. The X and Y coordinates will be the x,y pixel offsets on your map image where the item is located:

Item  X  Y
===========
Milk  50 50
Bread 20 40
etc..

Unfortunately, this will mostly be some manual work, though there are some tricks to help make it easier. For example, if it were me, I would output the store map image on a page and write some javascript to loop through all the items in the store. Have a click event listener to capture the current x,y mouse coords when i click on the image and increment to the next item. Then in the end I'd have a js object with all my items and x,y coords mapped out and I could easily move that to a database.

 

 

Then you make a form where the user can specify the list of items. You receive the list of items and then do a database query to get the X and Y coordinates for each item in the user specified.

 

Then you use the GD library to create an image resource with the map of the store as the canvas, and draw a point on the map using the x,y coordinates. Or overlap some icon or text onto the map, whatever you want to make it look like. Then you output the image. Just google for captcha or watermark tutorials, it's the same principle.

as far as showing what the "shortest path possible" to get the items is.. IMO that's probably a bit overkill for a store.  It's not like when you're driving somewhere and it's a much larger scale.. it's a store.  Any average person should be able to clearly see for themselves the "shortest path possible", and it will almost certainly involve just going from one end of the store to the other down the relevant isles.  For most people, the hassle of getting a list of items from a store is knowing where they are in the first place, which you'd be marking on the map.
 

Show you how? This would be a pretty complex project that would require quite a bit of time and energy. Especially depending on what you mean by "inside the store". If you mean like 3d imaging and being able to view and navigate around the store that would be expensive and complicated. It would be easiest just to take your own dimensions of the store get a drawing utility and draw a map. Then store the coordinates of the items in a database. Then you can run some algorithms to find the quickest route and locate items.

 

I am not looking for a 3D interface. I will try out what josh suggested it seems to be the solution for me.

 

Create a database table with 3 columns: one for item, another for X coordinate, and another for Y coordinate. The X and Y coordinates will be the x,y pixel offsets on your map image where the item is located:

Item  X  Y
===========
Milk  50 50
Bread 20 40
etc..

Unfortunately, this will mostly be some manual work, though there are some tricks to help make it easier. For example, if it were me, I would output the store map image on a page and write some javascript to loop through all the items in the store. Have a click event listener to capture the current x,y mouse coords when i click on the image and increment to the next item. Then in the end I'd have a js object with all my items and x,y coords mapped out and I could easily move that to a database.

 

 

Then you make a form where the user can specify the list of items. You receive the list of items and then do a database query to get the X and Y coordinates for each item in the user specified.

 

Then you use the GD library to create an image resource with the map of the store as the canvas, and draw a point on the map using the x,y coordinates. Or overlap some icon or text onto the map, whatever you want to make it look like. Then you output the image. Just google for captcha or watermark tutorials, it's the same principle.

 

Thanks josh, I will try this out and let you know if it works for me, I am an IB student so might not reply soon enough (this is for my Computer Science HL Dossier :P). And yes, I agree with you that a shortest route algorithm for a store will be an overkill, but in developing that i will implement some aspects of PHP that might fetch me a higher grade, so I will include it anyways

 

 

Thank You for such a quick response

 

 

Regards,

Makrand

For generating the map, have you considered something like jVectorMap:

http://jvectormap.com/examples/mall/

I dont want to make a map of the store via SVG. I will already have an image that contains the map and I will be marking the coordinates on it. I guess my thread title is a little misleading, sorry, my bad.

 

Mods, is there anyway to change it now?

 


IMO that's probably a bit overkill for a store.

 

On the contrary, but that's beside the point. :-)

 

Anyway, getting the shortest route will not require any special PHP things, it's "only" http://en.wikipedia.org/wiki/Dijkstra's_algorithm

Just make sure to store the possible connections between the coordinates, so you guide the customers around the shelves, not straight through them.

well yeah, i knew it was possible and that that people have already done the hard work involved in figuring out out the algorithm. My point was a matter of principle. It's not like finding shortest route across the country or even a town, where there are a million things to consider. Traffic, weather vs. road type. Speed limits. Stop signs. How often you stop for gas or potty breaks. Possibly getting lost or taking the wrong turn despite having a map.

 

It's a store. You can easily fit the entirety of it in your head, the only real variable being how many other people are shopping that day, which this map generator couldn't solve for anyways, short of tapping into the store cameras and doing some real-time evaluation of traffic flow.

 

As I said, the main reason people end up doing a lot more footwork than they need to in a store, is because they don't know where in the store the items are in the first place. So they spend extra time walking around looking for them. Then there are the people who mostly know where their stuff are located, and they have their list, but they don't really take the time to re-order the list based on location. This right here is the biggest gap in potential distance traveled. And most people will see that from having the map with the dots. Or even just having the reorganized list without the map.

 

So, handing someone a reorganized list is already good enough. Handing them a map with locations marked is slightly better since it would also show where on an aisle something is. But connecting the dots is overkill, and I guarantee you most everybody will look at the map and be like "no shit sherlock" about the lines. At best, it *might* save you a few feet, depending on how scattered things are around the store vs. aisle paths. Nobody would notice that difference, unless they go through some kind of excruciating pain every step they take, in which case, why the hell are they grocery shopping in the first place?

 

So IMO, even if someone else already did the hard part and you just have to essentially c/p the code into your script and let it do its thing, doesn't mean it's a good idea to add it in. And since OP said this is for a school assignment, all the more reason he shouldn't do it. If the OP were to take the time to work out the logic for himself and add it in, okay that would definitely give him brownie points. But I guarantee you c/p'ing some 3rd party snippet into the mix to make it look more shiny will NOT earn him more brownie points, and if anything, might possibly hurt him.

well yeah, i knew it was possible and that that people have already done the hard work involved in figuring out out the algorithm. My point was a matter of principle. It's not like finding shortest route across the country or even a town, where there are a million things to consider. Traffic, weather vs. road type. Speed limits. Stop signs. How often you stop for gas or potty breaks. Possibly getting lost or taking the wrong turn despite having a map.

 

It's a store. You can easily fit the entirety of it in your head, the only real variable being how many other people are shopping that day, which this map generator couldn't solve for anyways, short of tapping into the store cameras and doing some real-time evaluation of traffic flow.

 

As I said, the main reason people end up doing a lot more footwork than they need to in a store, is because they don't know where in the store the items are in the first place. So they spend extra time walking around looking for them. Then there are the people who mostly know where their stuff are located, and they have their list, but they don't really take the time to re-order the list based on location. This right here is the biggest gap in potential distance traveled. And most people will see that from having the map with the dots. Or even just having the reorganized list without the map.

 

So, handing someone a reorganized list is already good enough. Handing them a map with locations marked is slightly better since it would also show where on an aisle something is. But connecting the dots is overkill, and I guarantee you most everybody will look at the map and be like "no shit sherlock" about the lines. At best, it *might* save you a few feet, depending on how scattered things are around the store vs. aisle paths. Nobody would notice that difference, unless they go through some kind of excruciating pain every step they take, in which case, why the hell are they grocery shopping in the first place?

 

So IMO, even if someone else already did the hard part and you just have to essentially c/p the code into your script and let it do its thing, doesn't mean it's a good idea to add it in. And since OP said this is for a school assignment, all the more reason he shouldn't do it. If the OP were to take the time to work out the logic for himself and add it in, okay that would definitely give him brownie points. But I guarantee you c/p'ing some 3rd party snippet into the mix to make it look more shiny will NOT earn him more brownie points, and if anything, might possibly hurt him.

 

i agree that i will get some "no shit sherlock" comments, but it will add a Wow factor to the program as till date, i havent seen anyone do this, i asked my dad about it and even he hasnt seen it so far.

And i wont be using Djikstra's algorithm. i'll probably cook up a Nearest Neighbour algorithm or something similar. However, that is a secondary objective. 

 

Regards,

Makrand

 


And i wont be using Djikstra's algorithm. i'll probably cook up a Nearest Neighbour algorithm or something similar. 

 

Nearest neighbour will give you "a" route, not necessarily the shortest route the difference is small but key for your application.

 

You could also make things more interesting by including parameters like which products are the heaviest or most fragile. When I do my shopping I get the refridgerated items and drinks last, and I don't want to have eggs or cookies at the bottom of my shoppingcart.

 


a "too long; didn't read" offense

 

You underestimate me sir, I did read all of it. But what I distilled from it was "I don't see the point of  what you are doing" and "you should not use exiting code in school assignment". The first I don't agree with, and the second I think we all know already. Hence my surprise at the verbosity. But I have learned that you write long posts, so I'll compensate my interpretation in future.

 

Anyway, I don't want to start a discussion about this, so consider my remarks as never made.

Nearest neighbour will give you "a" route, not necessarily the shortest route the difference is small but key for your application.

 

You could also make things more interesting by including parameters like which products are the heaviest or most fragile. When I do my shopping I get the refridgerated items and drinks last, and I don't want to have eggs or cookies at the bottom of my shoppingcart.

Good suggestion. I will keep that in mind.

 

Thanks,

Makrand

dot josh tried to impart good sense

a laid out and structured defense

but advice went unread

for verbosity bred

a "too long; didn't read" offense

 

I'm sorry if i offended you. 

But as i mentioned earlier, this is a school project, not a real life application (i might implement it later, but no plans as of now)

What you said about the number of other shoppers on that day is 100% correct but i doubt that implementing that is within my capability. And i dont think i will even have enough time to do it :P

 

Regards,

Makrand

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.