Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  52] [ 6]  / answers: 1 / hits: 22059  / 13 Years ago, tue, november 29, 2011, 12:00:00

All,
I've got some locations stored in my database with long and lat coordinates. I'm debating between creating a map for each one of the locations or adding markers for all of them. Any advice would be appreciated on that idea but my issue is that I'm getting these values from my mySQL database. It looks like the only way you can actually add these is through javascript. Do I need to pass in the coordinates to a javascript function to create the markers? How would that look? Any suggestions are appreciated!


More From » php

 Answers
59

You're correct. You have to fetch the data from the database and use something along the line of:



  function initialize() {
var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $long; ?>);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById(map_canvas), myOptions);

var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:Hello World!
});
}


In a < script type=text/javascript>-tag on the page.
The above is taken from http://code.google.com/apis/maps/documentation/javascript/examples/marker-simple.html, so you'll have to adapt it to your needs.


[#88847] Monday, November 28, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;