Joni de Campos
Posts: 0
Joined: Fri Dec 11, 2015 12:21 pm

Show my location on Load jQuery Google Map Tutorial

Hi,

I want to show my location on the jQuery Google Map Tutorial (Building an app with Google Maps & geolocation).

So I invoke the geolocation1 service on Load after the initialize() javascript call on Load.

The problem is that works only the first time.

How can i force to show the location every time the App Loads ?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Show my location on Load jQuery Google Map Tutorial

Hello,

This event is triggered every app's load. You can change this event to "page show", which is triggered every time you open the page.

Joni de Campos
Posts: 0
Joined: Fri Dec 11, 2015 12:21 pm

Show my location on Load jQuery Google Map Tutorial

Hi Sergiy,

I put a alert() on the geolocation1 service javascript ( Success) to check if the coordinates are there and it is ok.

The javascript is being called, but the map is not updated.

Clicking on the Show My Location button the map is updated. Which calls the same service and javascript.

It seems to be missing something to refresh the map.

You can download the project here: http://is3d.com.br/appery/GuiaPesquei...

Joni de Campos
Posts: 0
Joined: Fri Dec 11, 2015 12:21 pm

Show my location on Load jQuery Google Map Tutorial

I found a code from Marina on another topic (https://getsatisfaction.com/apperyio/...

) and change the geolocation1 javascript to include it and make sure the map is loaded first:

I am going to make some test and return with the results.

Image

geolocation1 javascript:

function addMarkersAfterMapReady(mapName)

{
if (!Appery(mapName).gmap)
{
setTimeout(function () {addMarkersAfterMapReady(mapName);
}, 100);
} else

{
//Original geolocation javascript code

Code: Select all

     var markerLatLng = new google.maps.LatLng(Apperyio.storage.currentLat.get(), Apperyio.storage.currentLng.get()); 

var marker = new google.maps.Marker({
position: markerLatLng,
map: map,
icon: 'http://i.imgur.com/fDUI8bZ.png'
});

map.setCenter(markerLatLng);
map.setZoom(15);

Code: Select all

 } 

}
addMarkersAfterMapReady('google_map');

Return to “Issues”