I am working on an Android app using PhoneGap, and I need to display a marker on a Google map at a specific latitude and longitude. When the marker is clicked, I want to show an info window displaying the address associated with that location. However, the address being displayed is incorrect in my current code. What do I need to change to fix this issue?
var query = window.location.search.substring(1);
var parms = query.split('&');
var pos = parms[0].indexOf('=');
if (pos > 0) {
currentlat = parms[0].substring(pos + 1);
pos = parms[1].indexOf('=');
currentlong = parms[1].substring(pos + 1);
var orgplace = new google.maps.LatLng(currentlat, currentlong);
service.getDistanceMatrix(
{
origins: [orgplace],
destinations: datatblAcc,
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
}, callback);
function callback(response, status) {
var tblhtml = document.getElementById('listaddress');
if (status != google.maps.DistanceMatrixStatus.OK) {
document.getElementById('view-loadingpoi').style.display = "none";
} else {
setTimeout(function(){
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
var outputDiv = document.getElementById('outputDiv');
outputDiv.innerHTML = '';
deleteOverlays();
var data = '';
var localplace = new google.maps.LatLng(currentlat, currentlong);
if ((currentlat == 0))
{
localplace = new google.maps.LatLng(-65.994173, 78.127421);
currentlat = "-65.994173";
currentlong = "78.127421";
}
maploc = new google.maps.Map(document.getElementById("mapdisp"), {
center: localplace,
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
});
var image = 'images/greenpointer.png';
var pointcur = new google.maps.LatLng(currentlat, currentlong);
var marker = new google.maps.Marker({
position: pointcur,
icon: image,
map: maploc
});
google.maps.event.addListener(marker, "click", function (event) {
if (infowindow) infowindow.close();
var evelatitu = currentlong.split('.')[1];
if (((currentlat.replace(/^\s+|\s+$/g, '').indexOf(event.latLng.lat())) !== -1) && ((currentlong.replace(/^\s+|\s+$/g, '').indexOf(event.latLng.lng().toFixed(evelatitu.length))) !== -1)) {
var txthtml = "<div class='mappopuploc'>My Location<br/>" + response.originAddresses[0] + "</div>";
infowindow = new google.maps.InfoWindow({
content: txthtml
});
infowindow.open(maploc, marker);
}
});