views:

2008

answers:

8

I wrote a google map lookup page. Everthing worked fine until I referenced the page to use a master page. I removed the form tag from the master page as the search button on the map page is a submit button. Everything else on my page appears but the google map div appears with map navigation controls and logo but no map visuals appear.

I retested with the previous, non master page version and the map appears correctly. Any thoughts on what I'm missing?

A: 

One thing that can change when you add a master page is your elements ids.

if the div you are displaying the map in has runat='server' on it, you could have a problem. You would add that tag so you could manipulate the div from code-behind.

So, if my div looks like this:

If so, when you are initializing your map, you need to get the ClientId of the div. That would look like this: var mapDiv = '<%= gmap.ClientID %>'; var map = new GMap2(mapDiv);

Chris Brandsma
A: 

Good idea. This particular div happens to be a client side div so the id is static. When I look at the source of the page in the browser, I verified everything is there and the id fo the div is correct.

Next things to look at?

asp316
A: 

Load up FireFox and FireBug, start looking for javascript errors. One item that I have found, you have to call setCenter on the map for it to display. Also, if you are adding markers (or layers), you have to add the marker after you call setCenter.

Chris Brandsma
A: 

Ended up having to force the div to visible

See this thread on google maps support forums:

http://groups.google.com/group/Google-Maps-Troubleshooting/browse_thread/thread/0d27b66eef5f5d9e/1259a2991412f796?lnk=raot

Thanks!!

asp316
+1  A: 

Please view below Code and let me know its useful ...

MasterPage Code ( GMap.master page)

< body onload="initialize()"  onunload="GUnload()"  >  
< form id="form1" runat="server" >
    < div >
        < asp:contentplaceholder id="ContentPlaceHolder1" runat="server" >
        < /asp:contentplaceholder >
    < /div >
    < /form >
< /body >  

GMatTest.aspx Page which is used GMap.Master page

< %@ Page Language="C#" MasterPageFile="~/MasterPages/GMap.master" AutoEventWireup="true"
    CodeFile="GMapTest.aspx.cs" Inherits="GMapTest" Title="Google Map Page" % >


< asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server" >


    < script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=&lt; % = AppConfig.GoogleMapApiKey % >"
        type="text/javascript" >< /script >

    < script type="text/javascript" >

    var map = null;
    var geocoder = null;
    var latsgn = 1;
    var lgsgn = 1;
    var zm = 0; 
    var marker = null;    

    function initialize()
     {
      if (GBrowserIsCompatible()) 
      {
       var latitude=  "";
       var longitude= "";

       map = new GMap2(document.getElementById("map_canvas"));


         var center = new GLatLng(0,0);
         map.setCenter(center, 17);

         map.addControl(new GLargeMapControl());
        map.addControl(new GScaleControl());
        map.enableScrollWheelZoom();

        map.addControl(new GMapTypeControl());

        map.enableDoubleClickZoom();

         marker = new GMarker(center,{draggable: true});

         geocoder = new GClientGeocoder();


       GEvent.addListener(marker, "dragend", function() {
        var point = marker.getLatLng();
         marker.openInfoWindowHtml("Latitude: " + point.y + "< /br > Longitude: " + point.x  );
      });

       GEvent.addListener(marker, "click", function() {
        var point = marker.getLatLng();        

      });


        map.addOverlay(marker);
        GEvent.trigger(marker, "click");

        if (latitude  > 0 &&  longitude  > 0)
        {
        }
        else
        {       

            showAddress();

        }
      }
     }

Below porsion is continue so please copy it also

function showAddress() 
{
     var isAddressFound=false;  
     var companyAddress = '';  
     var address='satyam mall, vastrapur, ahmedabad, gujrat, india';  
     if (geocoder)   
    {  
         geocoder.getLatLng(address,function(point) {   
                             if (!point) {  
                            alert(address + " not found");  

                             } else {  
                                isAddressFound =true;  
                             map.setCenter(point,17);  
                             zm = 1;  
                             marker.setPoint(point);  
                             GEvent.trigger(marker, "click");  
                             }  
                         }  
         );  



//If address not found then redirect to company address

     if(!isAddressFound)
     {     
         geocoder.getLatLng(companyAddress,
         function(point) { 
         if (!point) { 
         } else {
            isAddressFound =true;
         map.setCenter(point,17);
         zm = 1;
         marker.setPoint(point);
         GEvent.trigger(marker, "click");
         }
         }
         );
     }
 }
}
< /script >

< div id="map_canvas" style="width: 100%; height: 425px" >
< /div >
< /asp:Content >
Note above code uses deprecated V2 version of Google Maps API.
Lee
A: 

Hello, i make a .aspx page for geocoding using google maps api.it works fine.but when i add master page to my project it stops working. can anyone tell me the soln???????? please mail me at [email protected] thanks

gul
A: 
gul
A: 

the code i used is <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Mapmash | Geocoder Tool | Geocode - Reverse Geocode - IP Geocode <%-- #map { height: 100%; } #hand_b { width:31px; height:31px; background-image: url(http://google.com/mapfiles/ms/t/Bsu.png); } #hand_b.selected { background-image: url(http://google.com/mapfiles/ms/t/Bsd.png); }

#placemark_b {
  width:31px;
  height:31px;
  background-image: url(http://google.com/mapfiles/ms/t/Bmu.png);
}
#placemark_b.selected {
  background-image: url(http://google.com/mapfiles/ms/t/Bmd.png);
}

#line_b {
  width:31px;
  height:31px;
  background-image: url(http://google.com/mapfiles/ms/t/Blu.png);
}
#line_b.selected {
  background-image: url(http://google.com/mapfiles/ms/t/Bld.png);
}

#shape_b {
  width:31px;
  height:31px;
  background-image: url(http://google.com/mapfiles/ms/t/Bpu.png);
}
#shape_b.selected {
  background-image: url(http://google.com/mapfiles/ms/t/Bpd.png);
}          
--> 
</style>
<style type="text/css">
v\:* {
  behavior:url(#default#VML);
}
</style>--%>
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAPkZq56tNYNmeuZjNQQ2p3hT0NZP-HbfQNNfWb9Z5SLbjZKYKwBTrGBqtttFmF2d-kWv2B2nqW_NyEQ"&gt;&lt;/script&gt;
<script type="text/javascript">
    google.load("maps", "2");
</script>
<script src="dragzoom.js" type="text/javascript"></script>
<script src="http://adserver.lat49.com/lat49/v0.10/lat49.js" type="text/javascript"></script>
<!-- Start of Google Analytics Code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2417064-1";
urchinTracker();
</script>
<!-- End of Google Analytics Code -->   
<script type="text/javascript">
//<![CDATA[
//rakf1 modified code taken from these 2 sources: - http://www.gorissen.info/Pierre/maps/googleMapLocationv4.php and - Distance Measurement Tool - Google Mapplets
// argItems code taken from 
// http://www.evolt.org/article/Javascript_to_Parse_URLs_in_the_Browser/17/14435/?format=print

var map;
var coordinates = '';
var geocoder = new GClientGeocoder();
var added = 0;
var marker;

function write_point() {
    var position = marker.getPoint();
    var lat = position.y.toFixed(6);
    var lng = position.x.toFixed(6);

    coordinates = lng + "," + lat + "\n";
    document.getElementById("attribute").value = 'lat="'+lat+'" lng="'+lng+'"';
    document.getElementById("latlng").value = '<lat>'+lat+'</lat>\n<lng>'+lng+'</lng>';
    document.getElementById("kml").value = lng+','+lat;
    document.getElementById("coord").value = marker.getPoint().toUrlValue();            
}

function get_address1() {
    GEvent.addListener(marker, "click", function(){
        var position = marker.getPoint();
        var lat = position.y.toFixed(6);
        var lng = position.x.toFixed(6);
        var html = 'FreeReverseGeo.com (~address):<br><iframe id="RSIFrame" name="RSIFrame" style="overflow:hidden; width:200px; height:55px; border: 1px" src="http://www.freereversegeo.com/gmap-api.php?lat_1=' + lat + '&lng_1=' + lng + '"></iframe><br>('+lat+','+lng+')';
        marker.openInfoWindowHtml(html);                    
    });     
}

function get_address() {
    GEvent.addListener(marker, "click", function(){
        var position = marker.getPoint();
        geocoder.getLocations(position, function(addresses) {
          if(addresses.Status.code != 200) {
            marker.openInfoWindowHtml("<b>Google Reverse Geocode:</b><br>Reverse geocoder failed to find an address for " + position.toUrlValue());
          }
          else {
            address = addresses.Placemark[0];
            var html = address.address;
            marker.openInfoWindowHtml("<b>Google Reverse Geocode:</b><br>"+html);
          }
        });                 
    });     
}


function my_location() {
    if (google.loader.ClientLocation) {
        var cl = google.loader.ClientLocation;
        var html = 'Google ClientLocation: <br><font size="+1">' + cl.address.city + ', ' + cl.address.region+ '<br> ' + cl.address.country+'</font><br>('+cl.latitude+','+cl.longitude+')'; 
        var point = new GLatLng(cl.latitude, cl.longitude);
        if(!marker) {
        map.setZoom(12);
        marker = new GMarker(point,{title: "Click to get address", draggable: true});
        map.addOverlay(marker); 
        added = 1;
        }
        map.setCenter(point);
        marker.setPoint(point);
        marker.openInfoWindowHtml(html);
    }
}

function draw_point() { 
    GEvent.addListener(map, 'click', function(overlay, point) {
        if (point && !added) {
            marker = new GMarker(point, {icon:G_DEFAULT_ICON, draggable: true, title: "Click to get address"});             
            map.addOverlay(marker);
            added = 1;
            GEvent.addListener(marker, "dragend", function(){
                write_point();
            }); 
        }
        else if (point && added) {
            marker.setPoint(point); 
        }
        write_point();
        get_address();
    });

}



function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 11);
        if(!marker) {
            marker = new GMarker(point, {icon:G_DEFAULT_ICON, draggable: true, title: "Click to get address"});             
            map.addOverlay(marker); 
            get_address();
            added = 1;
        }
        marker.setPoint(point); 
        write_point();
        }
    }
  );
}

function showLat49Ads(){
    Lat49.initAds(19);
    var center = map.getCenter();
    var lat = center.lat();
    var lng = center.lng();
    var zoomlevel = Lat49.Tile.convertGMap2Zoom(map.getZoom());
    Lat49.updateAdByLatLon("lat49ads", lat, lng, zoomlevel);
}

function load(){

    map = new GMap2(document.getElementById("map"),{draggableCursor: 'crosshair', draggingCursor: 'crosshair'});
    map.addControl(new GSmallZoomControl());
    map.addControl(new GMenuMapTypeControl(),new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(61,7)));
    map.addMapType(G_PHYSICAL_MAP);
    map.addControl(new GOverviewMapControl());
    var boxStyleOpts = { opacity: .2, border: "2px solid yellow" };         
    var otherOpts = {
      buttonHTML: "<img src='zoom-control-inactive1.png' title='Drag Zoom' />",
      buttonZoomingHTML: "<img src='zoom-control-active1.png' title='Drag Zoom: Cancel' />",
      buttonStartingStyle: {width: '15px', height: '15px'},
      overlayRemoveTime: 0 };
    map.addControl(new DragZoomControl(boxStyleOpts, otherOpts, {}), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(25,7)));
    map.setCenter(new GLatLng(37.35, -121.93), 12);

    draw_point();
    showLat49Ads();
    GEvent.addListener(map, "moveend", showLat49Ads);
 }
//]]>
</script>       




GeoCoder

Click on the map or search a place to add a marker and drag marker around to get marker position coordinates. Click on marker to get approximate address.
Coordinates (lat, lng): [for GLatLng]


Coordinates (lng, lat): [for KML]


Coordinates (lat="x.xx" lng="x.xx"):


Coordinates (<lat> <lng>):







if anyone have any idea regarding to code i posted earlier please inform me at [email protected] thanks

gul