473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

adding markers to my google maps...

i have a google maps api on my website, where when you click it grabs the lat/long coordinates and works well for me, but i would for a visual reference like to see a marker added to the place where i clicked do i know exactly where it is.. and i\'ve tried many different configurations.. any ideas?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  2. <script type="text/javascript">
  3.     var geocoder;
  4.     var map;
  5.  
  6. function initialize(){
  7.     var latlng = new google.maps.LatLng(36.879,-96.537);
  8.     var myOptions = {
  9.         zoom: 3,
  10.         center: latlng,
  11.         mapTypeId: google.maps.MapTypeId.HYBRID,
  12.         scaleControl: true,
  13.         navigationControl: true,
  14.         navigationControlOptions:{
  15.             style: google.maps.NavigationControlStyle.SMALL
  16.         },
  17.         mapTypeControl: true,
  18.         mapTypeControlOptions:{
  19.             style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
  20.         }
  21.     };
  22.         map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  23.         google.maps.event.addListener(map, 'mousedown', function(event){
  24.             findAddress(event.latLng);
  25.         });
  26.     }
  27.     function findAddress(loc){
  28.         geocoder = new google.maps.Geocoder(); 
  29.         if (geocoder){
  30.             geocoder.geocode({'latLng': loc}, function(results, status){
  31.                 if (status == google.maps.GeocoderStatus.OK){
  32.                     if (results[0]){
  33.                         address = results[0].formatted_address;
  34.                         document.getElementById('lat').value = loc.lat();
  35.                         document.getElementById('long').value = loc.lng();
  36.                     }
  37.                 }else{
  38.                     alert("Geocoder failed due to: " + status);
  39.                 }
  40.             });
  41.         }
  42.     }
  43.     var markers = new Array();
  44.     function addMarkers(){
  45.         var lats = document.getElementById('lats').value;
  46.         var lngs = document.getElementById('lngs').value;
  47.         var names = document.getElementById('names').value;
  48.         var descrs = document.getElementById('descrs').value;
  49.         var memid = document.getElementById('memid').value;
  50.  
  51.         var las = lats.split(";;")
  52.         var lgs = lngs.split(";;")
  53.         var dss = descrs.split(";;")
  54.         var usrn = memid.split(";;")
  55.  
  56.         for (i=0; i<las.length; i++){
  57.             if (las[i] != ""){
  58.                 var loc = new google.maps.LatLng(las[i],lgs[i]);
  59.                 var marker = new google.maps.Marker({
  60.                     position: loc, 
  61.                     map: window.map,
  62.                     title: nms[i]
  63.                 });
  64.                 markers[i] = marker;
  65.                 var contentString = [
  66.                   '<div id="tabs">',
  67.                   '<ul>',
  68.                     '<li><a href="#tab-2"><span>description</span></a></li>',
  69.                     '<li><a href="#tab-3"><span>location</span></a></li>',
  70.                   '</ul>',
  71.                   '<div id="tab-1">',
  72.                     '<p><h1>'+nms[i]+'</h1></p>',
  73.                   '</div>',
  74.                   '<div id="tab-2">',
  75.                    '<p><h1>'+nms[i]+'</h1></p>',
  76.                    '<p>Added by: '+usrn[i]+' from '+usrl[i]+'</p>'+
  77.                    '<p>'+dss[i]+'</p>'+
  78.                   '</div>',
  79.                   '<div id="tab-3">',
  80.                     '<p><h1>'+nms[i]+'</h1></p>',
  81.                   '</div>',
  82.                   '</div>'
  83.                 ].join('');
  84.                 var infowindow = new google.maps.InfoWindow;
  85.                 bindInfoWindow(marker, window.map, infowindow, contentString);
  86.             }
  87.         }
  88.     }
  89.     function bindInfoWindow(marker, map, infoWindow, contentString){
  90.         google.maps.event.addListener(marker, 'mouseover', function() {
  91.             map.setCenter(marker.getPosition());
  92.             infoWindow.setContent(contentString);
  93.             infoWindow.open(map, marker);
  94.             $("#tabs").tabs();
  95.          });
  96.     }
  97.     function highlightMarker(index){
  98.         for (i=0; i<markers.length; i++){
  99.             if (i == index){
  100.                 markers[i].setZIndex(10);
  101.                 markers[i].setIcon('http://www.google.com/mapfiles/arrow.png');
  102.             }else{
  103.                 markers[i].setZIndex(2);
  104.                 markers[i].setIcon('http://www.google.com/mapfiles/marker.png');
  105.             }
  106.         }
  107.     }
  108. </script>
  109.  
you see at the end i have a markers function with locations to the pics and still nothing.. thanks for any help gt
Dec 5 '11 #1
1 2694
omerbutt
638 512MB
hey ,
why dont you use googleearth to see the right code, it generates the code for the markers you are talking about. simply add a marker and then generate code it would give you all the script , hoping that it uses the same api.
regards,
Omer Aslam
Dec 5 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Sean | last post by:
Have you ever wanted to add the great features inherent in Google Maps? Here is how you do it. ============== == STEP ONE == ============== Create a new MS Access form called frmGoogleMap....
6
by: JimInOC | last post by:
Does anyone have any idea as to how google loads pieces of images together so as you drag new image pieces are loaded from the server? I haven't had much luck finding any articles on it. thanks
3
by: Lemon Tree | last post by:
Hi everybody. I am new to Javascript so probably I am asking something trivial, but I cannot see where there problem is. Or, better. Maybe I know where the problem is but I cannot find a...
2
by: jobo | last post by:
I'm sure there's some way to do this simply but I'm new to Javascript. So I'm creating an application that interacts with google maps and everytime the user pans around the map I want it to send...
0
by: joaorbraposo | last post by:
Hi! I'm creating an application using C# and I need to display one or more markers in a webBrowser object using Google Maps. The problem is that I was thinking to create only one HTML file...
1
by: SyPhy | last post by:
Hi all, First post to this group and I hope I can get some help. I have been stuck on this all day.... I am using the Google Maps API to plot markers grouped into categories via checkboxes....
4
by: iceanfire | last post by:
On the backend I have a python script that gets two pieces of information from the database: 1. html 2. xml file The javascript is supposed to : 1. inject the html file into a div 2. use the...
5
by: Nike1984 | last post by:
I'm fairly new to Javascript and it's more of a guessing game for me... I'm trying to build an app for Google Maps and just had some issues recently. First off I just wanted to say that everything...
0
by: Ashriya | last post by:
Hi All, I have developed a Google maps application in which there are a few markers. On mouse over of those markers, I need to show certain data. The map is placed inside the iframe of a window. The...
6
by: mfaisalwarraich | last post by:
Hi everyone, I am trying to add multiple pinpoint to google map using Lon/Lat. All addresses will be fetched from mysql database using PHP. I have looked at google and searched for it on...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.