Monday 3 February 2014

How to create numbered markers in Google Map

Hello Everyone ,

Here is simplest solution for creating numbered markers for google map,

You can use any platform for this solution , here i am using django, python.
 

Create a view that takes integer as a parameter .


from django.http import HttpResponse
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw

def map_imagepin(request,num):
  
    font = ImageFont.truetype("arial.ttf", 11)

    text = str(num)
   
    if len(text)==1:
        text_pos = (16,13)
    elif len(text) ==2:
        text_pos = (13,13)
    elif len(text)==3:
        text_pos = (11,13)
    tcolor = (255,255,255)
    img = Image.open(r"c:\icon-pin.png")
    draw = ImageDraw.Draw(img)
    draw.text(text_pos, text, fill=tcolor,font=font)
    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    return response


Here is urls.py

urlpatterns = patterns('',
    url(r'^/image/(\d+)/$', map_imagepin),
)



This view takes image from local location and add label to it , and return it in to the response.
Use this url  http://127.0.0.1:8000/mapimg/111/


Here is my original image ,
 Here is the edited image ,




3 comments: