Script 1:
<script type="text/javascript">
var markers;
function fnSetCustomMarkers()
{
init_map('my_map', 1.56, 103.65, 14);
}
function init_map(map_canvas_id, lat, lng, zoomLevel)
{
var myLatLng = new google.maps.LatLng(lat, lng);
var options = {
zoom: zoomLevel,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map_canvas = document.getElementById(map_canvas_id);
var map = new google.maps.Map(map_canvas, options);
var infowindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
var markers1 = [];
for (var i = 0; i < markers.length; i++)
{
var marker = new google.maps.Marker(markers[i]);
markers1.push(marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
bounds.extend(marker.getPosition());
}
var markerCluster = new MarkerClusterer(map, markers1);
}
</script>
Script 2:
<script>
(function ()
{
google.load("maps", "2");
google.setOnLoadCallback(function () {
// Create map
var v = document.getElementById("Label1").innerHTML; //Label status
var map = new google.maps.Map2(document.getElementById("map")),
//Read marker text from asp label
markerText = document.getElementById("Label1").innerHTML = v,
markOutLocation = function (lat, long) {
var latLong = new google.maps.LatLng(lat, long),
marker = new google.maps.Marker(latLong);
map.setCenter(latLong, 13);
map.addOverlay(marker);
marker.openInfoWindow(markerText);
google.maps.Event.addListener(marker, "click", function () {
marker.openInfoWindow(markerText);
});
};
map.setUIToDefault();
// Check for geolocation support
if (navigator.geolocation) {
// Get current position
navigator.geolocation.getCurrentPosition(function (position) {
// Success!
markOutLocation(position.coords.latitude, position.coords.longitude);
var lat = '<%= TextBox2.ClientID %>';
var lon = '<%= TextBox3.ClientID %>';
document.getElementById(lon).value = position.coords.longitude;
document.getElementById(lat).value = position.coords.latitude;
var geocoder = geocoder = new GClientGeocoder();
var coord = position.coords.latitude+","+position.coords.longitude;
geocoder.getLocations(coord, addAddressToMap);
//Get address
function addAddressToMap(response)
{
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
var add = '<%= TextBox4.ClientID %>';
document.getElementById(add).value = place.address;
var add2 = '<%= Label5.ClientID %>';
document.getElementById(add2).innerText = place.address;
}
},
function () {
// Gelocation fallback: Defaults to Stockholm, Sweden
markerText = "<p>Please accept geolocation for me to be able to find you. <br>I've put you in Stockholm for now.</p>";
markOutLocation(59.3325215, 18.0643818);
}
);
}
else {
// No geolocation fallback: Defaults to Eeaster Island, Chile
markerText = "<p>No location support. Try Easter Island for now. :-)</p>";
markOutLocation(-27.121192, -109.366424);
}
});
})();
</script>
my question:
1- how to join Script 1 to Script 2..
2- Script 1 is the script that will get the data (latlong) from database, & plot it in the google map using marker
3- Script 2 is geolocation function.
4- i want to join Script 1 to Script 2,so that i will get result:
- 1st the code will run the geolocation function like usual.
- then i will add the button. when user click the button, it will call
script 2 which it will plot the marker (latlong from database) to the map
by not losing the marker from Script 1 (which is our location).
- all the marker displayed on the map, have the function
marker.openInfoWindow which the detail can be add here.