5 Replies Latest reply on Jul 2, 2013 8:09 AM by thetrickster888

    Lat Long Shows Wrong Result In Business Catalyst

    SohalK Level 1

      Hi All,

       

      We created a custom map on BC where we use lat and long to point the place on the map. However, in the case of Long Island the result always goes to the middle of the sea. Any ideas on how to rectify this?

       

      Thanks.

        • 1. Re: Lat Long Shows Wrong Result In Business Catalyst
          thetrickster888 Level 4

          BC generates lat and long from the address and zip code fields.  Sometimes these aren't always accurate I've found.  Basically, when you save a web app item, BC goes out to a geocoding service and submits your address and zip code and in return they get latitude and longitudes.  I'm not sure if it's the geocoding service or BC but the accuracy is questionable, in my opinion.  If you can, double check that your address info is correct.  If you are using 5 digit zip codes, try the longer zip codes for certain areas where you have accuracy issues.

           

          If you still run into problems, I suggest creating a custom latitude and longitude field in your web app and roll your own google maps implementation.  In your javascript you should check for your custom lat and long first and use those to plot addresses and then if you don't find custom latitude and longitude I would pass your address information to google maps' geocoding service which is very accurate to plot points on your custom rolled google map.

           

          I've had good success with differnt types of addresses for web apps. Some of my web app address cases are there is no address information (like area 51) or I only have lat and long or I only have a city name, etc.

           

          You can see a demo at http://www.chrismatthias.com/demos/google-maps-web-app-demo

           

          The script that powers the demo which you can look at or steal is at http://www.chrismatthias.com/js/bc-web-app-map-demo.js

           

          If anyone else has any ideas how to fix his inaccurate lat and long from BC's geocoder, please chime in but I find it a little too unreliable.

          • 2. Re: Lat Long Shows Wrong Result In Business Catalyst
            Liam Dilley Adobe Community Professional & MVP

            The lat long tags only render data if you have a state.

            • 3. Re: Lat Long Shows Wrong Result In Business Catalyst
              SohalK Level 1

              Thanks Chris - We have created a custom map lat and longitude for the website and even put in our on lat long fields. It still shows it wrong

               

              The address is actually an island. As you can see below it is getting the right lat and longitude but showing up differently on the map.

               

                <script type="text/javascript">var switchTo5x=true;</script>

                      <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>

                      <script type="text/javascript">stLight.options({publisher: "ur-e097dbc1-ed4c-c65a-3a1e-3f4ace568475", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

                      <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

                      <script>

                    var geocoder;

                    var map;

                    function initialize() {

                      geocoder = new google.maps.Geocoder();

                      var latlng = new google.maps.LatLng(-20.393926,148.873329);

                      var mapOptions = {

                        zoom: 15,

                        center: latlng,

                        mapTypeId: google.maps.MapTypeId.ROADMAP

                      }

                      map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

                      codeAddress('-20.393926,148.873329');

                    }





                    function codeAddress(address) {

                      geocoder.geocode( { 'address': address}, function(results, status) {

                        if (status == google.maps.GeocoderStatus.OK) {

                          map.setCenter(results[0].geometry.location);

                          var marker = new google.maps.Marker({

                              map: map,

                              position: results[0].geometry.location

                          });

                        } else {

                          alert('Geocode was not successful for the following reason: ' + status);

                        }

                      });

                    }

                  </script>

                      <script type="text/javascript">

               

               

              I agree with you that BC's mapping is quite off when it comes to addresses.

               

              BTW - the demo is great. Probably going to use it on our next maps project.

              • 4. Re: Lat Long Shows Wrong Result In Business Catalyst
                Liam Dilley Adobe Community Professional & MVP

                Are you using the Lattitude & Longitude Tags? to render those values in your script?

                • 5. Re: Lat Long Shows Wrong Result In Business Catalyst
                  thetrickster888 Level 4

                  I think you are using the "codeAddress()" function wrong.  That function takes and address string like "1600 Pennsylvania Ave. Washington, D.C." NOT a lat and long.

                   

                  If you look at my demo and check out the "setupMarkers()" function, that function is fired during the "initialize()" function which is run on page load.  The "setupMarkers()" function finds each web app item on the page and loops through each one.  When it is looping through your web app items it is looking for "data" attributes on those items.  For my demo I have two places for lat and long in my item's data attributes.  "data-address-latitude" is where I output BC's generated lat and long and "data-latitude" is a custom field in the web app just in case I only have lat and longitude and no address information.

                   

                  The "setupMarkers()" function first combines the "data-street", "data-city", "data-state" and "data-zip" attributes on my web app item to create a full address string.  Then, i check to see if there is any data in my custom "data-latitude" and "data-longitude" attributes. If there's no custom lat or long (meaning I didn't specifically add the custom lat and long to the web app item" it will use the "codeAddress()" function to go out to Google's geocoding service and generate more accurate lat and long from the address string we created.

                   

                  The code is a little hard to follow and I didn't comment it but one day I will make this into a jquery plugin with instructions.

                   

                  Just make sure you are using the codeAddress function correctly by passing in an address string.