email btw is a href="mailto:jbrucestuart@comcast.net" rel="nofollow"jbrucestuart@comcast.net/a
email btw is a href="mailto:jbrucestuart@comcast.net" rel="nofollow"jbrucestuart@comcast.net/a
Hello Bruce
About the google map issue that I mentioned above.
I think the response form forum can't help me.
(I am not a coding base guy,the javascript is hard to me.)
Can you give me some advices?
In my APP,user can create own diving spot.
when user click the button "find spot" will open a popup of map.
user can use "show on me" or "show my location" to find the location probably.
example:Taipei,Taiwan
then user can use the map to modify the location accurately,and the location's lat/len will show on the popup input label.
(by click on map or just get the canter location's lat/len)
when user click the button "ok",the lat/len information will save in localstorage variables.
I can handle with the First and third step,but still can't figure out how to let second step worked.
looking for your help again!!
Spark,
First piece of advice - in order to be really effective here - you're going to need to get it on with Javascript
It needs to become your buddy. You can do the basics without it - but anything beyond super basic - you'll need the foundation. I'd recommend hitting up w3schools.com - ( example post there : http://www.w3schools.com/jsref/jsref_... ) . It can help you become very proficient - very quickly.
Now - on to your questions - the if question is how can the user modify the location of a marker - here's where I learned how to do exactly that:
(Post with details forthcoming in a few minutes):
First - highly recommended reading for the google maps user:
https://developers.google.com/maps/do...
Sorry for the delay - for a draggable marker - you need to set it's property to dragable when you declare it (or you can set it via a method call);
Here's a declaration of a google map marker - that is dragable:
Code: Select all
omarker = new google.maps.Marker({
position: oposition,
map: omap,
draggable: true,
title: sname + "id:" + sid,
animation: google.maps.Animation.DROP,
icon: 'http://maps.google.com/mapfiles/kml/p...'
});
// wait here till the marker is complete...
do
{
setTimeout( f_wait , 1000);
}
while (!omarker );
note - that in the title - you could also put the position of the marker and other text.
Once you add the fact that it is dragable, in the declaration or via a method call you then need to add a 'listener' event (essentially your custom code that runs when the marker is moved somewhat like this:)
google.maps.event.addListener( omarker , 'dragend', function( ) {
console.log('moving marker with title: ' + omarker.getTitle() + " to new position:" + " Lat: " + omarker.getPosition.lat() + " Long: " + omarker.getPosition.lng() );
} );
If you want to refer to the position of a marker - you can do it like so:
omarker:getPosition() (which will return a lat, lng goggle position object)
if you want to get the lat and long from the marker you can say:
var oposition = omarker.getPosition()
if you wanted to display the lat and lng in the title of the marker - you could - in the issue the statement : (after you've declared the variable omarker above...)
omarker.setTitle("Position Lat: " + omarker.getPosition.lat() + " Long: " + omarker.getPosition.lng() );
Complete set of methods , etc. - in the documentation link I sent above.
Best,
Bruce
Dear Bruce
very thanks for your suggestion to learn more about Javascript!!!
I already try study Javascript by book and the website you mentioned.
Hope someday I can teach somebody just like you share your knowledge!!!
I will try to follow your steps to get the lat/len of google map first.
Thanks again!!!
Bruce
should I add the code "draggle" on the map component in click event for run Javascript ?
Second question is if I want to get the lat and long from the marker.
I can add the code below which you mentioned .
var oposition = omarker.getPosition()
but how can I set the localstorage variables?
thanks~~
Spark - sorry for the delay.... if you want to get the lat and land from the marker - the code is:
nsomevarlat = oposition.lat() ;
nsomevarlong = oposition.lng()
or skipping the shortcut....
var nsomevarlat = omarker.getPosition().lat()
var nsomevarlong = omarker.getPosition().lng()
visit the Google maps API for a bit more information on the Marker object and the position object (which is what comes back from the getPosition() call above)...
it lists all the methods for both objects - and the properties as well....
i'm going to pull some of my marker code from my project that's on ice to help answer the other question on drag events... it will take a bit... later tonight.