gfxpixeldesigns
Privileged
-
Joined
-
Last visited
Reputation Activity
-
Read the documentation. If you read through it, you'll learn how to work with the Maps API.
There is no cut and paste with Google Maps API, you kinda just have to read through and work it out for yourself. If you have a basic understanding of Javascript it shouldn't be too difficult
http://code.google.com/apis/maps/documentation/javascript/tutorial.html
-
They're using v2.0, which is deprecated, so eventually it will be turned off altogether. So you're best off using v.3.0.
You're not reading the documentation properly, then, because it includes examples that do what you want. In fact, the following even goes one step further, removing the need for someone to enter their address and finding it for them using Geolocation:
http://code.google.com/apis/maps/documentation/javascript/examples/map-geolocation.html
If you don't want that though, this is the one:
http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html
Now, that doesn't allow the user to click on the map - but what it would do is plot a marker based on the address they've entered into your form, which saves them time anyway.
If you absolutely want it so the user places a marker, read this:
http://code.google.com/apis/maps/documentation/javascript/events.html
It tells you how to use Javascript to interpret a user click action.
Here's an example, though you will want to change it to disallow multiple locations:
http://code.google.com/apis/maps/documentation/javascript/examples/event-arguments.html
You'll also need to think about how you pass that markers location through your form as I presume you will need to know where they've clicked? If I was you I'd do this by writing the Javascript so it takes the Longitude/Latitude of the markers location and inserts that info into a hidden text field when the user clicks. You'd then be able to use that to find where they placed the marker.
Hope that all makes sense. Like I said there's no "out of the box" ready-made way to do what you want, you're gonna need to brush up on your javascript and figure most of it out for yourself. Gmaps API is really hard though so I feel for you! If I could help more I would. Good luck!
-
Have you tried echo'ing the address the user inputs into a hidden form field on page 2? Then just use your maps code as usual, pulling the address from that field.
Edit: Bare in mind that'd be POST, not GET.
-
Why would you need the field again on the second page?! You're over-complicating things.
And...I'm sorry but if you insist on using GET, I can't really help you, as I only have experience doing this using POST.
Also, you can't really use AutoComplete for addresses so far as I know....
-
This is how I do it.
<input type="text" id="from" name="from" value="" placeholder="Enter airport name, city or ICAO" class="required" AUTOCOMPLETE=OFF>
This value is then echo'd on the following page. Because with my setup, the form is submitted BEFORE the map, I hide the form field. However as you're submitting AFTER the map, just use one of your existing fields.
<input id="address1" style="visibility:hidden" type="textbox" value="<?php echo $_POST["from"]; ?>">
I loop through three addresses and GeoCode them, you'll only be using one so you don't need the loop, but here it is anyway.
locations = [document.getElementById('address1').value, document.getElementById('address3').value, document.getElementById('address2').value];
function addMarkers(locations) { var geocoder = new google.maps.Geocoder(); // Loop through locations array for (var i = 0; i < locations.length; i++) { // Use geocode service to find latlng geocoder.geocode( { 'address': locations[i] }, drawGeodesic(locations[i], i)); } }
And that, works perfectly, and is pretty much identical in function to what you're trying to do.
-
If someone has already entered their address, you do NOT need to show the field again. You're gonna confuse people into thinking they need to enter it again. Hide it. You can echo it in your text though if you wish to show them what they entered.
Read above, I've told you how to do it.
-
/sigh.
I've told you not to use the loop, but you are. My code is purely there as an example, not for you to just copy and paste. Doesn't work like that. You need to grab the value from the input on page 2 and Geocode it.
If you are using method=POST on the first form it should echo the value fine on page two providing you are using PHP. It won't work now because your second page is just HTML. It needs to be a PHP page. PHP won't work on .html.
Save pasting my full code, which I won't and can't do, this is about as much guidance as I can give to you, sorry!
-
Essentially, POST the value to the second page which needs to be a PHP page.
Echo the value in a hidden input field on the second page.
Pull that value into your Google Maps code, Geocode, plot on the map.
Think about it, if you can tap an address into an input and plot it on the map, then that's essentially what Page 2 does but instead of a field you can see and type in, it's a hidden field with the value from the first page.
You'll want to use onLoad so it shows up when page 2 loads.
-
Right, cos today I'm feeling super generous, I've done it for you.
This is your code for the first form. I've left the id's blank, change as appropriate for your styling.
<form id="" name="" action=".php" method="post"> <input type="text" id="address" name="address" value=""> <button id="" type="submit">Submit</button> </form>
Secondly, your second page MUST be PHP, i.e. the filename ends .php not .html. This code then goes into your head:
<script type="text/javascript"> var geocoder; var map; function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } function codeAddress() { var address = document.getElementById("address").value; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location }); } else { alert("Geocode was not successful for the following reason: " + status); } }); } </script>
You then need to have your map initialize on load, which you do by changing this:
<body>
To this: ON THE SECOND PAGE.
<body onload="initialize();">
Then, somewhere, anywhere on the second page, put this:
<input id="address" style="visibility:hidden" type="textbox" value="<?php echo $_POST["address"]; ?>">
That box will not show, it's hidden by CSS, so you don't need to worry where it is, as long as it's between the body tags.
That definitely, 100% works. The only thing it won't do is plot a marker on the location entered. You'll need to work that out for yourself. Just like ALL the above, how to plot a marker is documented in the Maps v3 API.
Please consider re-writing this code yourself rather than purely copy and pasting, it would be worth your time understanding what I've done here and how.
Good luck, and a few plus ones would be nice
-
gfxpixeldesigns reacted to henbast in SQL ORDER BY not working ?Change to:
$readresult=$write->query("SELECT title, created_time, identifier, post_content FROM aw_blog WHERE status=1 ORDER BY identifier LIMIT 5");//select from db last 5 post
ORDER BY needs to go after the WHERE clause.
-
gfxpixeldesigns got a reaction from pbul2004 in Clients Requests - Whats the best way to go about this?Just done a quick google search...
http://forum.opencart.com/viewtopic.php?t=3991
About half way down they start getting into the integration, havent read it all but it looks like there on the right track with that.
-
gfxpixeldesigns reacted to Jay Gilford in php truncate help<?php $out .= substr(apply_filters('the_content', get_the_content('Read more')), 0, 100); ?>
-
gfxpixeldesigns reacted to Skateside in Form input box onclick set value to ""I wrote a topic explaining this problem a little while ago. It talks through how to do it and why to do it that way. The script at the bottom of the first post will do the job you're looking for.
Clearing the Value of Form Elements