0
votes

I have an android application in phonegap , it's a google maps , it shows me my current location , i have a draggable marker in my position and an infoWindow showing my latitude and my longitude.

var map;
var marker;
var infowindowPhoto = new google.maps.InfoWindow();
var latPosition;
var longPosition;

function initialize() {

var mapOptions = {
    zoom: 8,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: new google.maps.LatLng(10,10)
};

map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

initializeMarker();
}

function initializeMarker() {

if (navigator.geolocation) {

    navigator.geolocation.getCurrentPosition(function (position) {

        var pos = new google.maps.LatLng(position.coords.latitude,  position.coords.longitude);

        latPosition = position.coords.latitude;
        longPosition = position.coords.longitude;

        marker = new google.maps.Marker({
            position: pos,
            draggable: true,
            animation: google.maps.Animation.DROP,
            map: map
        });

        map.setCenter(pos);
        updatePosition();

        google.maps.event.addListener(marker, 'click', function (event) {
            updatePosition();
        });

        google.maps.event.addListener(marker, 'dragend', function (event) {
            updatePosition();
        });
    });
}
}


function updatePosition() {

latPosition = marker.getPosition().lat();
longPosition = marker.getPosition().lng();

contentString = '<div id="iwContent">Lat: <span id="latbox">' + latPosition + '</span><br />Lng: <span id="lngbox">' + longPosition + '</span></div>';

infowindowPhoto.setContent(contentString);
infowindowPhoto.open(map, marker);
}

initialize();

http://jsfiddle.net/upsidown/d3toa81m/

My problem that I want to show my address instead of my latitude and my longitude in my infoWindow. I find this tutorial https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse . My problem with this tutorial that i don't want to add this:

<input id="latlng" type="text" value="40.714224,-73.961452">
  <input type="button" value="Reverse Geocode" onclick="codeLatLng()">

and if I don't add this the function "codeLatLng()" doesn't work. What should I do to show my address in my infowindow.

1

1 Answers

0
votes

you are getting the grid coordinate from google maps. Once you get the grid, have you tried to use curl to scrap google maps for the city and state? I am about to do the same thing, good luck.