Solved

Styled Google Maps

Posted on 2013-10-30
5
227 Views
Last Modified: 2013-11-25
I'm trying to change the map colour in the right nav on this page according to Google's specifications here under the 'Style Array Example' with grey features and blue roads.

I've tried everything it says, but still can't get it to work.

Here's the HTML:
          <div style="width:100%;height:215px;background:url(http://maps.google.com/maps/api/staticmap?center=<%=server.URLEncode(""&rs("ca_postcode"))%>&zoom=14&size=350x350&maptype=roadmap&markers=color:ORANGE|label:A|<%=server.URLEncode(""&rs("ca_postcode"))%>&sensor=false) center no-repeat;"></div>

Open in new window

0
Comment
Question by:UName10
  • 2
5 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39612166
This is very similar to the question you posted here.

Here is a working example based on that question's posted code, incorporating the code you posted. I changed the inline server side code to real numbers for the sake of the example.
<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps -- Styled Map</title> 
   <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
</head> 
<body onLoad="initialize()"> 
      <div id="map-canvas" style="width:100%;height:215px;background:url(http://maps.google.com/maps/api/staticmap?center=55.6468,37.581&zoom=14&size=350x350&maptype=roadmap&markers=color:ORANGE|label:A55.6468,37.581&sensor=false) center no-repeat;"></div>

<script type="text/javascript">
function initialize() {

  // Create an array of styles.
  var styles = [
    {
      stylers: [
        { hue: "#00ffe6" },
        { saturation: -20 }
      ]
    },{
      featureType: "road",
      elementType: "geometry",
      stylers: [
        { lightness: 100 },
        { visibility: "simplified" }
      ]
    },{
      featureType: "road",
      elementType: "labels",
      stylers: [
        { visibility: "off" }
      ]
    }
  ];

  // Create a new StyledMapType object, passing it the array of styles,
  // as well as the name to be displayed on the map type control.
  var styledMap = new google.maps.StyledMapType(styles,
    {name: "Styled Map"});

  // Create a map object, and include the MapTypeId to add
  // to the map type control.
  var mapOptions = {
    zoom: 14,
    center: new google.maps.LatLng(55.6468, 37.581),
    mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
    }
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),
    mapOptions);

  //Associate the styled map with the MapTypeId and set it to display.
  map.mapTypes.set('map_style', styledMap);
  map.setMapTypeId('map_style');
}
</script>
          
</body> 
</html>

Open in new window

0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 39612286
In looking at the link you provided, the inline server side code (<%=server.URLEncode(""&rs("ca_postcode"))%>) is producing this: CM15+8AG,
which is not something Google Maps is going to be able to translate into longitude/latitude coordinates.

Also, you cannot, as far as I know, style a map generated from a link. You have to create a styled map using the Google Maps API as I have demonstrated. Basically, most of what you have in that div is not being used in my example. This is really all that matters:
<div id="map-canvas" style="width:100%;height:215px;"></div>
The script does the rest.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39674333
I've requested that this question be closed as follows:

Accepted answer: 500 points for tommyBoy's comment #a39612166

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Closing Comment

by:UName10
ID: 39674334
Valid answer for a complex question
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question