PDA

View Full Version : map shows mountain view, ca before loading my info



clabasky
18 Nov 2011, 2:44 PM
hello Sencha friends!

I have a map on my app that shows a route between two locations. The issue is that the map shows mountain view, ca for about a second before loading my custom map :-/ Any advice would be awesome~!!!




var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Loading..."});
myMask.show();
postcard.setActiveItem(mappanel);

//grab location from record
var getaddress = postdetailcard.data.address;
var getzipcode = postdetailcard.data.zipcode;
var getcity = postdetailcard.data.city;


//geocode address
var address = getaddress +', '+ getcity+', '+ getzipcode;
var geocoder = new google.maps.Geocoder();

geocoder.geocode({'address': address}, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {


var coord = results[0].geometry.location;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;


directionsDisplay = new google.maps.DirectionsRenderer();

var lat = locationstore.data.items[0].data.latitude;
var lng = locationstore.data.items[0].data.longitude;

var start = lat+','+lng;
var end = coord;

var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};

directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);


var image = 'logo-map-sm.png';

//show marker
var marker = new google.maps.Marker({
map: map,
position: coord,
icon: image
});

var myOptions ={
zoom: 14,
center: coord,
mapTypeId: google.maps.MapTypeId.ROADMAP
}


//creates map
var map = new google.maps.Map(document.getElementById("detailmap"), myOptions);
directionsDisplay.setMap(map);
}
});


myMask.hide();
}
else {
alert("Geocode fail" + status);
myMask.hide();
}
});

clabasky
18 Nov 2011, 2:45 PM
this is in my controller

tim@locateaware.com
20 May 2014, 8:41 AM
I have the same problem and wondered if anyone has a workaround ? I'm using ST2.3 and in the maprender event I'm setting the map center to the current location, however when the view initially loads for a second or two the map is centered on Mountain View before the maprender event kicks in.

I'd like it so that map initially renders with the correct position, but can't see to find a way. Any help appreciated.

My maprender event:


var gmap = map.getMap();

if(gmap !== null) {
var center = new google.maps.LatLng(MyApp.app.currentLat, MyApp.app.currentLng);
var marker = new google.maps.Marker({
position: center,
title: 'My Location',
map: gmap
});
gmap.setCenter(center);

}