Grzegorz
Grzegorz

Reputation: 3608

GoogleMap shows different location each day

I'm tryin to sort out why google maps behave diffrently after than a day before.

I recently put my customer's website online. There was an error with geolocation and I fixed it. Did not fix it on test site tho.

Today, on both sides (fixed one and test one) my geolocation started to show searched location in center of Africa. I'm really clueless what's going on. It works, next day it doesn't.

Not saying it also stopped showing YellowPin, why?

        var map;
        var mapOptions;
        var markerOwn = null;
        function searchLocations()
        {

            var address = document.getElementById('addressInput').value;
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({address: address}, function(results, status) {

                if (status == google.maps.GeocoderStatus.OK){
                    if(markerOwn === null){
                        markerOwn = new google.maps.Marker({
                            map: map,
                            position: new google.maps.LatLng(50, 20),
                            customInfo: "<br><center><b>Jesteś Tutaj!</b></center>",
                            flat: false,

                            icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/ylw-pushpin.png', // user :)

                            title: "Twoja lokacja",

                        });
                        addInfoWindow(markerOwn);
                    } 
                    markerOwn.setPosition( new google.maps.LatLng(results[0].geometry.location.ob, results[0].geometry.location.pb ) );
                    google.maps.event.trigger(markerOwn,'click');
                    map.panTo(results[0].geometry.location);
                }
            });

        }

You can see code in action here: http://spafoodbistro.pl/index.php?page=gdzie-jestesmy

Edit: What I changed earlier was in

 markerOwn.setPosition( new google.maps.LatLng(results[0].geometry.location.ob, results[0].geometry.location.pb ) );

earlier I used different value to fetch coordinates, now I use:

 results[0].geometry.location.ob to get it.

Why it changes? maybe that's whats wrong since it changed last time?

Upvotes: 0

Views: 131

Answers (1)

MichaC
MichaC

Reputation: 13390

Seems you mix up latitude and longitude, and results[0].geometry.location is already a LatLng object, so you can simply use

markerOwn.setPosition(results[0].geometry.location);

Which works for me.

Upvotes: 2

Related Questions